hello, i m working on H.264 encoder, i m new to dis and if anyone can suggest me how to code using c code then i m more thankful to them... plz let me know how to open a binary file using c, i have tried and have got zero errors but end result its not opening :(
c code to open a binary/raw video file
Collapse
X
-
Tags: None
-
-
Code:#include <stdio.h> #include <stdlib.h> int main() { char *buffer ; FILE *fh, *fs ; fh= fopen("display name.c", "rb"); fs= fopen (" loadout.c","w"); if (fs==NULL) { fseek(fh, 0L, SEEK_END); long s = ftell(fh); rewind(fh); buffer == malloc(s); if ( buffer != NULL ) { fread(buffer, s, 1, fh); // we can now close the file fclose(fh); fh = NULL; // do something, e.g. fwrite(buffer, s, 1, stdout); free(buffer); } if (fh != NULL) fclose(fh); } return EXIT_SUCCESS; }Last edited by Rabbit; Oct 10 '13, 06:01 PM. Reason: Please use [CODE] and [/CODE] tags when posting code or formatted data.Comment
-
This code does not work:
First, you meant the assignment operator.Code:buffer == malloc(s);
Second, malloc returns void* and this cannot be assigned to a char* uness you use a cast:
Third, this code:Code:buffer = (char*)malloc(s);
probably wants to be:Code:if (fs==NULL) { fseek(fh, 0L, SEEK_END); long s = ftell(fh); rewind(fh); etc...
because if fs is zero, your file did not open.Code:if (fs!=NULL) { fseek(fh, 0L, SEEK_END); long s = ftell(fh); rewind(fh); etc...
I got everything to compile but did not run the codeComment
Comment