So I'm working on recover for pset 4, and when I run the current version of the program, nothing happens and it doesn't seem to even end.

//declare outptr;
    FILE* outptr = NULL;

//define the block buffer

BYTE buffer[512];

//initialize for new filename below
    int count = 0;  
    int counter[3] = {0,0,0};
    char* title = NULL;

    //read 1 block into buffer
   fwrite(&buffer, 512, 1, inptr);

    //check to see if new jpg sequence is there
    if( new_jpg(buffer) == true)
        //close current file if one has been opened
        if(title != NULL)

        //make title using current counter value
        sprintf(title, "%i%i%i.jpg", counter[0], counter[1], counter[2]);

        //open new file with new title
        outptr = fopen(title, "a");

        //make sure correct opening

        if (outptr == NULL)
            printf("Could not open %s", title);
            return 3;

        //increment counter for next file

        int tens = (count / 10) % 10;
        int ones = count % 10;
        counter[2] = ones;
        counter[1] = tens;


    //already found a jpg?

    else if(title==NULL)
        //do nothing and loop back to move to next block (do I need to use   fseek here?)

    else if(title != NULL)
        //add buffer to current outfile
        fwrite(&buffer, 512, 1, outptr);

while (!feof(inptr));

//close current outfile


//close infile


  return 0;

What could that mean? Is it somehow wrapped up in the loop? If so, why isn't it creating any new files?


It usually means that you have an infinite loop.

Your do while loop is dependent of finding EOF on your infile, or file you are reading from, but you never actually read from this file, you have two fwrite() calls but no fread() call so your program never encounters that EOF flag.

At the beginning of your loop you might want to change that fwrite() call to an fread() so that you actually start reading from your inpointer.

You must log in to answer this question.

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