#include
#include
int main()
{
FILE *f;
char filename[20];
char line[100];
int returnvar=1;
while(returnvar==1)
{
printf("Enter Filename:");
//scanf("%s",filename);
gets(filename);
if((f=fopen(filename,"r"))!=NULL)
{
printf("ERROR! FILE NAA NA!!\n");
returnvar=1;
}
else if((f=fopen(filename,"w"))==NULL)
{
printf("ERROR CREATING FILE\n");
returnvar=1;
}
else
{
printf("FILE CREATED\n");
f=fopen(filename,"w");
printf("Write a line Please:");
gets(line);
fprintf(f,"%s",line);
//pFile = fopen ("myfile.txt" , "r");
f=fopen(filename,"r");
fgets (line , 100 , f);
// printf("ang sulat sa file:");
puts(line);
// puts("\n\nThe line you entered is/are: [ %s ]\n",line);
break;
}
}
fclose(f);
return 0;
}
No comments:
Post a Comment