Thursday, 13 November 2014

Creating a Text File in C

 In c there are two types of files.
  1.       Text files
  2.       Binary files

Text files store human readable characters while binary files store machine readable characters.

main( )
    FILE *f;
    char s1[25];
    int i;
    f = fopen("abc.txt","w");
    /* open for writing ..second parameter specifies the mode. */
    strcpy(s1,"This is an example line.");

    for (i = 1; i <= 10; i++)
      fprintf(f,"%s Line number %d\n", s1, i);
    fclose(f); /* close the file before ending program */

Sponsored Links

Popular Posts



Google+ Followers

Google+ Badge