I have been working on a problem that is driving me crazy. The fgets now returns null strings instead of the strings in the file it is reading. I extracted the code to the simplest snippet (below). I have changed my gcc from 3.4 to 4.1.1, reloaded all libraries I can identify in cygwin. fgets does work on stdin. My environment is Windows Server 2003 running Cygwin with gcc compiler. The only thing I can say that changed was the installation of gdb 6.5 (debugger) which I loaded to troubleshoot another problem (which I found and fixed). So, what libraries should I be looking at?
Your help will be greatly appreciated.
Thanks,
Leon
Here's sample code:
Code:
#include <stdio.h>
char ch[100];
char temp_str[200];
char read_string[200];
FILE *conf_file;
int main(void)
{
printf("enter a string to test the fgets function on stdin: ");
fgets(ch,100,stdin);
printf("stdin string is: %s\n",ch);
/* open the config file*/
sprintf(temp_str, "D:\\c_projects\\logs.c");
conf_file = fopen(temp_str, "r");
if (conf_file == NULL)
{
printf("fatal error - failed to open file: %s", temp_str);
exit(1);
}
if (feof(conf_file))
{
printf("end of file encountered\n");
exit(1);
}
printf("file: %s has been opened\n", temp_str);
while ( fgets(read_string, strlen(read_string), conf_file) != NULL)
{
if (ferror(conf_file))
{
printf("read config fail error\n");
exit(1);
}
printf("read_string is: %s\n", read_string);
}
}