as

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.


#include<stdio.h>             
#include<string.h>
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 */
}








No comments:

Post a Comment

Leave your valuable feedback. Your thoughts do matter to us.

Sponsored Links

Popular Posts

Comments

ShareThis