I've been struggling with this bug for a while. I'm using windows 10 and code::blocks 16.01 MinGW.

I want to compare c to an end line character. 

One program on my system runs successfully, just to skip the header line of a file: 

```
while(c!='\n')
{
    c = fgetc(traverse);
    if(c == EOF)
        return(1);
}

```

where traverse was opened using 

```
fopen("traverse.dat", "r");

```

however, my other programs:

```
FILE * infile;

/* Open a large CSV */
infile = fopen("Getty_Megatem.csv", "r");
if(infile == NULL)
{
    printf("no file");
    return(EXIT_FAILURE);
}
char c = 0;
int i = 0;

/* Opens file successfully */
printf("File opened\n");

/* Count commas in first line */
while(c != '\n');
{
    c = fgetc(infile);
    if(c == ',')
        i++;
    if(c == EOF)
        return(EXIT_FAILURE);
}

printf("Number of commas: %i\n", i);

fclose(infile);

return(EXIT_SUCCESS);

```

and

```
ifstream infile;
char c;
string mystr;

infile.open("ostring.dat");

// Skip a line
while (c!= '\n')
    infile >> c;

getline(infile, mystr);

```

and (the one I REALLY want to work)

```
ifstream emdata;

string firstline;
char c = 0;
int i = 0;

vector<double> vdata;

// redundancy 
vdata.reserve(10000);

// There are ~ 300 doubles per line
emdata.open("Getty_Megatem.csv");

// Skip first line
getline(emdata, firstline);

while(c != '\n' && c != EOF)
{
    emdata >> vdata[i] >> c;
    cout << vdata[i] << ",";
    i++;

    if(i == 999)
    {
        cout << "\n\ni>9999";
        break;
    }
}

emdata.close();
return 0;

```

are unsuccessful, they compile and execute then read the stream forever - or until my maximum iterations 9999 is reached. All these files contain new lines.