Study of file i/o - 3 Writing strings to a file with fputs( ).

#include <stdio.h>

int main(void)
{
FILE *fp;
char name[30];
int x;

fp = fopen("names" , "w");

if(fp == NULL)
{
printf("\nUnable to create/open file for writing");
return 1;
}

for(x = 1 ; x <= 5 ; x++)
{
printf("Name :");
gets(name);
fputs(name, fp);
}

fclose(fp);

return 0;
}

No comments:

Post a Comment

kiss on google ads if you are anonymous because your ip is trackable.thank you.

......from.admin