hi i am writing a program that reads integers(signed or unsigend) from file.
my input file contains these numbers(without brackets)
[41 35 -66 -124 -31 108 -42 -82 82 -112 73 -15 -15 -69 -23]
and my code is:
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <string.h>
main()
{
FILE * hFile;
int c;
long n = 0;
hFile = fopen("input15Numbers.txt", "r");
if (hFile == NULL)
{
printf("Failed to Open the File");
}
else
{
while (!feof(hFile)) {
c = fgetc (hFile);
if (c != ' ')
{
fscanf (hFile, "%i", &c);
printf("%i", c);
printf("\n");
}
fclose(hFile);
getch();
}
}
But it produce wrong out put when i print it..
Output:
1
5
66
124
31
0
-42
82
2
112
3
15
15
69
23
printing some values correctly but not all, what i am doing wrong here????