Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: fopetesl on January 12, 2019, 02:43:29 pm

Title: GCC no Debug and fscanf problem
Post by: fopetesl on January 12, 2019, 02:43:29 pm
I have a binary file begins:
Code
01 C8 01 FD 01 FB 01 F1 01 F3 01 F7 01 F6 01 F1 01 F4 01 FB 01 F4 01 FB 01 FA 01 F6 01 F7 01 F5
i.e. 16 bit integers, so array[0] = 0x1C8

In the past I have used GCC on LINUX and read/write files without any problem, though still a 'C' novice.
So, this compiles without error:
Code
    while((pDirent = readdir(dir)) != NULL) {
//      printf ("[%s]\n", pDirent->d_name);
      if( !strncmp( pDirent->d_name, "baseline.bas",11) ) {
        printf("Found baseline!\n");
      }
    }
    if( Readbase = fopen("baseline.bas","rb") == NULL)
        printf("Open Baseline failed\n");
    else
        printf("Open Baseline success\n");
    _getch();  // so I can see result
    rewind(Readbase);
    ii = i2 = 0;
    while( fscanf( Readbase,"%x",&ii) != -1) {
      printf("%x ",ii);
      basefile[i2++] = ii;
    }
    basefile[i2] = 0;        /* insurance! */
    uDataPoints = i2;
    printf("\nRead %d points\n", uDataPoints);
Output:
Code
 Directory: C:\BIN2CSV\Binary2csv
Open Baseline success

Read 0 points

Process returned 0 (0x0)   execution time : 14.418 s
Press any key to continue.

Almost identical  code from a LINUX compile ran without problem, so I've muffed it somewhere but cannot see how.

Also I set up the project with Debug turned off. How to turn it on?
Title: Re: GCC no Debug and fscanf problem
Post by: oBFusCATed on January 12, 2019, 03:17:32 pm
Also I set up the project with Debug turned off. How to turn it on?
http://wiki.codeblocks.org/index.php/Debugging_with_Code::Blocks
Title: Re: GCC no Debug and fscanf problem
Post by: fopetesl on January 12, 2019, 03:24:40 pm
Yes. I've been there but the option "Debug" isn't available and adding the "-g" option doesn't enable it.
Title: Re: GCC no Debug and fscanf problem
Post by: oBFusCATed on January 12, 2019, 07:31:00 pm
What do you mean by there? Do you have a project? Do you have a debug target in the build options? If you don't have one you should create one...
Title: Re: GCC no Debug and fscanf problem
Post by: fopetesl on January 13, 2019, 09:59:32 am
I don't know what is bad in my original code but I worked around it using fprintf() :)
I recreated the project but this time included Debug option.
Thanks for the input.