i am trying to read a text file like this and store each number as an integer (without the decimals) and print them
1 3 5.6 3 2.1 4
2 2 3 4.2 1
here is what i have now
#include <stdio.h>
#include <conio.h>
void main()
{
int i, n=1;
int n1=0,n2=0,n3=0,n4=0,n5=0,n6=0,n7=0,n8=0,n9=0,n10=0;
char c[10];
FILE *f1;
f1=fopen("textfile.txt","r");
while(fgets(c,10,f1)!=NULL)
{
sscanf(c,"%d %d %d %d %d %d %d %d %d %d", &n1, &n2, &n3, &n4, &n5, &n6, &n7, &n8, &n9, &n10);
printf("%d %d %d %d %d %d %d %d %d %d\n",n1,n2,n3,n4,n5,n6,n7,n8,n9,n10);
getch();
}
but the output i get is always
1 3 5 0 0 0 0 0 0 0
2 2 3 4 0 0 0 0 0 0
its basically ignoring everything else once the sscanf encounters a decimal
Any suggestions??
Thanks