yep, thats exacly what I mean. been searching for answer for like 3 days now.
yep, thats exacly what I mean. been searching for answer for like 3 days now.
Ummm... did you try looking in your textbooks and library documentation? Really opening a file is pretty basic stuff usually covered in some depth in any good tutorial or textbook. The library docs for your compiler should have fleshed out the details for you....
You probably should sit down with a textbook or good tutorial (from the web) and work it page by page, example by example, as a deliberate study... I'm betting you'll be glad you did.
Last edited by CommonTater; 10-03-2011 at 03:45 PM.
Code:FILE* pFile=fopen("yourfilename","rb"); long lSize=your_work_getfilesizefrom(pFile); char * buffer=malloc(lSize); if( fread( buffer , lSize, 1, pFile ) ) puts("OK"); else perror("yourfilename");
your_work_getfilesizefrom(pFile); ???
If you say so....
You can seek to the end of the file to get the file size if you don't want to use an OS function like stat() for example. But in this case the easiest thing to do is probably a blocking fgetc/fputc loop one character at a time, simple (but slow).
Code:int tmp; while( (tmp = fgetc(infile)) != EOF ) { fputc(tmp, outfile); }
Last edited by Subsonics; 10-03-2011 at 04:21 PM. Reason: Messed up the order in fputc