Panel użytkownika
Nazwa użytkownika:
Hasło:
Nie masz jeszcze konta?

Access violation reading location 0xCCCCCCCC

Ostatnio zmodyfikowano 2016-10-28 00:38
Autor Wiadomość
klaphson
Temat założony przez niniejszego użytkownika
Access violation reading location 0xCCCCCCCC
» 2016-10-27 22:41:34
w linku screen: http://oi65.tinypic.com/14npw7t.jpg

Unhandled exception at 0x00CF19FA in ConsoleApplication3.exe: 0xC0000005: Access violation reading location 0xCCCCCCCC.

C/C++
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

void wykres( int, float *, float *, char * );
float * prostokatx( struct sygnal s3 );
float * prostokaty( struct sygnal s3 );
struct sygnal {
    float amplituda, czas_syg, okres, sczas, czest_syg;
    int czest_prob, sczest_prob, lokres;
    float * tabx, * taby;
};
int main() {
    struct sygnal s3;
   
   
    printf( "Podaj dane: \n" );
    printf( "Amplituda: \n" );
    scanf( "%f", & s3.amplituda );
    printf( "Czestotliwosc sygnalu: \n" );
    scanf( "%f", & s3.czest_syg );
    printf( "Czestotliwosc probkowania: \n" );
    scanf( "%d", & s3.czest_prob );
    printf( "Czas trwania: \n" );
    scanf( "%f", & s3.czas_syg );
    printf( " Amplituda = %f, Czestotliwosc sygnalu=%f,  Czestotliwosc probkowania=%d, Czas sygnalu=%f \n", s3.amplituda, s3.czest_syg, s3.czest_prob, s3.czas_syg );
   
    s3.okres = 1 / s3.czest_syg;
    s3.sczas = s3.okres / s3.czest_prob;
    s3.lokres =( int ) ceil( s3.czas_syg / s3.okres );
    s3.sczest_prob = s3.czest_prob * s3.lokres;
    prostokatx( s3 );
    prostokaty( s3 );
    wykres( s3.sczest_prob, s3.tabx, s3.taby, "wykres.html" );
   
    system( "pause" );
    return 0;
}

float * prostokatx( struct sygnal s3 )
{ int i = 0;
    s3.tabx =( float * ) malloc(( size_t ) s3.sczest_prob * sizeof( float ) );
   
   
   
    for( i = 0; i < s3.sczest_prob; i++ ) {
        s3.tabx[ i ] = i * s3.sczas;
       
       
        return s3.tabx;
       
       
       
    }
}
float * prostokaty( struct sygnal s3 )
{ int i = 0;
    s3.taby =( float * ) malloc(( size_t ) s3.sczest_prob * sizeof( float ) );
    for( i = 0; i < s3.sczest_prob; i++ ) {
        s3.taby[ i ] = s3.amplituda;
       
        return s3.taby;
    }
}



void wykres( int l, float * tx, float * ty, char nazwa[] ) { //funkcja generujaca kod html dla wykresu Google Chart
    FILE * fp;
    int i;
   
   
   
   
    printf( "Rysuj %s\n", nazwa );
    fp = fopen( nazwa, "w" );
    fprintf( fp, "<html>\n" );
    fprintf( fp, "<head>\n" );
    fprintf( fp, "<script type=\"text/javascript\" src=\"https://www.google.com/jsapi\"></script>\n" );
    fprintf( fp, "<script type=\"text/javascript\">\n" );
    fprintf( fp, "google.load(\"visualization\", \"1\", {packages:[\"corechart\"]});\n" );
    fprintf( fp, "google.setOnLoadCallback(drawChart);\n" );
    fprintf( fp, "function drawChart() {\n" );
    fprintf( fp, "var data = google.visualization.arrayToDataTable([\n" );
   
    fprintf( fp, "['i', 'Wartosc'],\n" );
    for( i = 0; i < l; i++ ) {
        fprintf( fp, "[%f, %f],\n", tx[ i ], ty[ i ] ); //przekazanie danych na wykres
    }
    fprintf( fp, "[%f, %f]\n", tx[ i - 1 ], ty[ i - 1 ] );
    fprintf( fp, "]);\n" );
   
    fprintf( fp, "var options = {\n" );
    fprintf( fp, "title: 'Wybrany sygnal'\n" );
    fprintf( fp, "};\n" );
   
    fprintf( fp, "var chart = new google.visualization.LineChart(document.getElementById('chart_div'));\n" );
    fprintf( fp, "chart.draw(data, options);\n" );
    fprintf( fp, "}\n" );
    fprintf( fp, "</script>\n" );
    fprintf( fp, "</head>\n" );
    fprintf( fp, "<body>\n" );
    fprintf( fp, "<div id=\"chart_div\" style=\"width: 900px; height: 500px;\"></div>\n" );
    fprintf( fp, "</body>\n" );
    fprintf( fp, "</html>\n" );
   
    fclose( fp );
   
    system( nazwa ); //uruchomienie pliku html
}
[ cpp ]
P-153000
michal11
» 2016-10-27 22:56:55
Coś jest nie tak z tx i ty, wygląda jak by były nie zaalokowane.
P-153003
klaphson
Temat założony przez niniejszego użytkownika
» 2016-10-27 23:25:51
zrobiłem teraz tak, dalej ten sam błąd :(

C/C++
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

void wykres( struct sygnal s3, char nazwa[] );
float * prostokatx( struct sygnal s3 );
float * prostokaty( struct sygnal s3 );
struct sygnal {
    float amplituda, czas_syg, okres, sczas, czest_syg;
    int czest_prob, sczest_prob, lokres;
    float * tabx, * taby;
};
int main() {
    struct sygnal s3;
   
   
    printf( "Podaj dane: \n" );
    printf( "Amplituda: \n" );
    scanf( "%f", & s3.amplituda );
    printf( "Czestotliwosc sygnalu: \n" );
    scanf( "%f", & s3.czest_syg );
    printf( "Czestotliwosc probkowania: \n" );
    scanf( "%d", & s3.czest_prob );
    printf( "Czas trwania: \n" );
    scanf( "%f", & s3.czas_syg );
    printf( " Amplituda = %f, Czestotliwosc sygnalu=%f,  Czestotliwosc probkowania=%d, Czas sygnalu=%f \n", s3.amplituda, s3.czest_syg, s3.czest_prob, s3.czas_syg );
   
    s3.okres = 1 / s3.czest_syg;
    s3.sczas = s3.okres / s3.czest_prob;
    s3.lokres =( int ) ceil( s3.czas_syg / s3.okres );
    s3.sczest_prob = s3.czest_prob * s3.lokres;
    prostokatx( s3 );
    prostokaty( s3 );
    wykres( s3, "wykres.html" );
   
    system( "pause" );
    return 0;
}

float * prostokatx( struct sygnal s3 )
{ int i = 0;
    s3.tabx =( float * ) malloc(( size_t ) s3.sczest_prob * sizeof( float ) );
   
   
   
    for( i = 0; i < s3.sczest_prob; i++ ) {
        s3.tabx[ i ] = i * s3.sczas;
    }
    return s3.tabx;
}
float * prostokaty( struct sygnal s3 )
{ int i = 0;
    s3.taby =( float * ) malloc(( size_t ) s3.sczest_prob * sizeof( float ) );
    for( i = 0; i < s3.sczest_prob; i++ ) {
        s3.taby[ i ] = s3.amplituda;
    }
    return s3.taby;
}



void wykres( struct sygnal s3, char nazwa[] ) { //funkcja generujaca kod html dla wykresu Google Chart
    FILE * fp;
    int i;
   
   
   
   
    printf( "Rysuj %s\n", nazwa );
    fp = fopen( nazwa, "w" );
    fprintf( fp, "<html>\n" );
    fprintf( fp, "<head>\n" );
    fprintf( fp, "<script type=\"text/javascript\" src=\"https://www.google.com/jsapi\"></script>\n" );
    fprintf( fp, "<script type=\"text/javascript\">\n" );
    fprintf( fp, "google.load(\"visualization\", \"1\", {packages:[\"corechart\"]});\n" );
    fprintf( fp, "google.setOnLoadCallback(drawChart);\n" );
    fprintf( fp, "function drawChart() {\n" );
    fprintf( fp, "var data = google.visualization.arrayToDataTable([\n" );
   
    fprintf( fp, "['i', 'Wartosc'],\n" );
    for( i = 0; i < s3.sczest_prob; i++ ) {
        fprintf( fp, "[%f, %f],\n", s3.tabx[ i ], s3.taby[ i ] ); //przekazanie danych na wykres
    }
    fprintf( fp, "[%f, %f]\n", s3.tabx[ i - 1 ], s3.taby[ i - 1 ] );
    fprintf( fp, "]);\n" );
   
    fprintf( fp, "var options = {\n" );
    fprintf( fp, "title: 'Wybrany sygnal'\n" );
    fprintf( fp, "};\n" );
   
    fprintf( fp, "var chart = new google.visualization.LineChart(document.getElementById('chart_div'));\n" );
    fprintf( fp, "chart.draw(data, options);\n" );
    fprintf( fp, "}\n" );
    fprintf( fp, "</script>\n" );
    fprintf( fp, "</head>\n" );
    fprintf( fp, "<body>\n" );
    fprintf( fp, "<div id=\"chart_div\" style=\"width: 900px; height: 500px;\"></div>\n" );
    fprintf( fp, "</body>\n" );
    fprintf( fp, "</html>\n" );
   
    fclose( fp );
   
    system( nazwa ); //uruchomienie pliku html
}
[ cpp ]
P-153004
pekfos
» 2016-10-28 00:38:28
C/C++
float * prostokatx( struct sygnal s3 )
{ int i = 0;
    s3.tabx =( float * ) malloc(( size_t ) s3.sczest_prob * sizeof( float ) );
Przekazujesz strukturę przez wartość, zmiany które wprowadzasz są lokalne.
P-153006
« 1 »
  Strona 1 z 1