C file input/output: Difference between revisions

Content deleted Content added
Dkasak (talk | contribs)
Corrected the code snippet.
Dkasak (talk | contribs)
mNo edit summary
Line 35:
Writing and appending modes will create a file to write to in the case that the file name doesn't already exist. However, the operation of fopen is undefined if the filename doesn't follow requirements by the OS. For example, if the filename contains illegal characters , the program might crash. For example, in windows \ /: * ? < > and | cannot be part of a file name.
 
A convenient, but '''non-standard''', way to find the length of a file in C is:
<pre>
#include <stdio.h>
Line 41:
int main(void)
{
intlong length;
FILE *f = fopen("filename", "r");
Line 47:
length = ftell(f);
fclose(f);
printf("%dld\n", length);
return 0;