It's a good idea to compile with warnings:
Code:
gcc -Wall -Werror -o program program.c
Gives me this warning:
program.c:10:23: error: comparison of distinct pointer types lacks a cast [-Werror]
program.c:10:23: error: comparison with string literal results in unspecified behavior [-Werror=address]
That will give you a big hint of where to look. Here is a fixed version:
Code:
#include <stdio.h>
int main()
{
FILE *salesmanPtr;
char buffer;
salesmanPtr = fopen("salesman.txt","r");
while(fscanf(salesmanPtr, "%c", &buffer) != EOF)
{
if (buffer == '\n')
break;
printf("%c\n",buffer);
}
return 0;
}