0

The error that I get is \ expected an exit code of 0, not output of "ÿØÿà\u0000\u0010JFIF\u0000\u0001\u0002..."

Everything is running and operating properly

#include <stdio.h>
#include <stdint.h>
int main(int argc, char* argv[])
{
    //opening input file
    FILE* inptr = fopen("card.raw", "rb");
    if (inptr == NULL)
    {
        printf("Could not open card");
        return 1;
    }

    //some declarations
    uint8_t buffer[512];
    int counter = 0;
    char title[8];
    FILE* outptr = NULL;

    //the real logic
    while(fread(&buffer, 512, 1, inptr)==1)
    {
        //checkin dem conditions
        if (buffer[0]== 0xff && buffer[1]== 0xd8 && buffer[2]==0xff && (buffer[3]>=224 && buffer[3]<=239))
        {
            sprintf(title, "%03d.jpg", counter);
            outptr = fopen(title, "a");
            if (outptr == NULL)
            {
                printf("cannot open outfile\n");
                return 2;
            }
            counter++;
        }
        //to check if it is not at the start 
        if(outptr!=NULL)
            fwrite(&buffer,512,1,outptr);
    }

    fclose(inptr);
    fclose(outptr);
}
2
  • Why have you opened the output file in "append" mode? You should use the "write" mode. – abhishek Jun 17 '16 at 20:12
  • That's not the problem – MARS Jun 17 '16 at 22:10
1

I think I already is what happens, you do not close the jpg file when you find a new one:

if (buffer[0]== 0xff ......
{
    // Close a jpg file if it is open
     if ( outptr != NULL)
            {
                fclose(outptr);
            } 
}

do not know how I did not see before, sorry

1
  • That seemed to do the trick. Thanks understood the problem – NbrKn Jun 19 '16 at 12:12
0

Check50 is already telling you what the problem is, you don't have a return value on successful execution of program.

3
  • Thanks for replying. Have already tried doing that but receive the same error. And anyway isnt it supposed to give a return value of 0 on successful execution by default? – NbrKn Jun 18 '16 at 6:12
  • No, it doesn't do it by default, you have to specify a return value. Where did you put the return 0 line? It should be right before the last } at the bottom. And are you getting the correct number of jpg's, all properly labelled? – ronga Jun 18 '16 at 8:36
  • I was getting the correct number of jpg's, no problem there – NbrKn Jun 19 '16 at 12:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .