I am having a problem with my C code. See the code below:
#include<stdio.h>
int main()
{
char name[30]; // Declaring the string-array
FILE* fileptr; // Declaring the FILE pointer
char file[10];
printf("Please enter the file name : ");
scanf("%s",file);//Taking a single word input
fileptr = fopen(file,"w");
if (fileptr == NULL)
{
printf("No such file found !");
}
puts("Please enter some strings here: ");
gets(name); //Line 17
fputs(name,fileptr);
printf("\nStrings saved to %s",file);
fclose(fileptr);
}
The problem is in Line 17 I used gets() instead of scanf() but I don't know if it's right or not. I can't get any user input here using gets() or other functions. But I want to have multiple word or line string input and the skips after printing the line 16 & then it prints line 19. It doesn't gives me any chance for the input. What should I do? Please help me out. Thanks in advance. :)