How do I check if I already opened a jpeg file to write to? I could declare an int outside of the loop that I set to 1 if I open a file, but I think there must be another way... Some kind of function to check if I already have opened a file to write to..?

My pseudocode:

    open card image
    iterate over card image, store 512b in buffer
        if beginning of jpeg
           if file open, append to it 
           else open new jpeg file and append to it
            if file open, append to it   (this line here)
            else dont do anything
        if no 512 B read
            append to last and close file
   close file
   return 0

Supposing that before the loop you declare the file where you will write data

FILE *jpgfile = NULL;

You can use

if (jpgfile != NULL)

to check if you have an already open file.

You must log in to answer this question.

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