Hi, I have some trouble in reading the filename. For some reason, my program wouldn't continue on after inputting the filename, even after pressing enter. I have purposely enter the a printf command with "Hello" for test, but it never show up. Whats worse is that I could even type on the next line after I press enter.
Here is my code:
Code:
int main()
{
struct database_input data[99999];
char inputconnectfilename[260];
char *p;
FILE *InputConnectionFile;
printf("Please input the full filename of the network data file \n");
printf("(Note: Must be in the same directory as this program)\n");
fgets(inputconnectfilename, sizeof(inputconnectfilename), stdin);
if ((p = strchr(inputconnectfilename, '\n')) != NULL)
*p = '\0';
if((InputConnectionFile = fopen(inputconnectfilename, "r")) == NULL)
{
perror("Failed to open the file");
exit(1);
}
prinf("Hello"); /* use for testing*/
...
and here is my output:
[firyace]$ gcc -Wall projectmain.c -lm
[firyace]$ ./a.out
Please input the full filename of the network data file
(Note: Must be in the same directory as this program)
test.dat
Please tell me what to do to fix this problem.
Thanks!