Hi,
im filling a 2D array using fscanf and reading from a csv file.
the problem is the file im reading from has some blank spaces which causes any information following to be output as an error.
Is there any way of ignoring the blank spaces in the csv file (excel) and continuing to the next number?
# include<stdio.h >
# include <stdlib.h>
# include<math.h>
int ReadFromFile(in t Array[][30], FILE *inFile);
int main(void)
{
double arrayVal;
int Array[30][30], i, j, x;
char filename[50];
for(i=0;i<28;i+ +)
{
for(j=0;j<28;j+ +)
{
Array[i][j]=0;
}
}
//Get input filename
printf("Enter the filename to read:");
scanf("%50s",fi lename);
//Open file
FILE *inFile;
inFile = fopen(filename, "r");
if(inFile==NULL )
{
printf("Could not properly load file!\n");
getchar();
getchar();
}
else
{
printf("File opened and loaded properly\n\n");
}
for(i=0;i<28;i+ +)
{
for(j=0;j<28;j+ +)
{
Array[i][j]= ReadFromFile(Ar ray, inFile);
printf("The Array Value at Point %d,%d=%i\n", i+1, j+1, Array[i][j]);
}
fscanf(inFile," \n");
}
fclose(inFile);
getchar();
getchar();
}
int ReadFromFile(in t Array[][30], FILE *inFile)
{
int value;
fscanf(inFile," %i,", &value);
printf("the value=%i\n", value);
return (value);
}
thanks
im filling a 2D array using fscanf and reading from a csv file.
the problem is the file im reading from has some blank spaces which causes any information following to be output as an error.
Is there any way of ignoring the blank spaces in the csv file (excel) and continuing to the next number?
# include<stdio.h >
# include <stdlib.h>
# include<math.h>
int ReadFromFile(in t Array[][30], FILE *inFile);
int main(void)
{
double arrayVal;
int Array[30][30], i, j, x;
char filename[50];
for(i=0;i<28;i+ +)
{
for(j=0;j<28;j+ +)
{
Array[i][j]=0;
}
}
//Get input filename
printf("Enter the filename to read:");
scanf("%50s",fi lename);
//Open file
FILE *inFile;
inFile = fopen(filename, "r");
if(inFile==NULL )
{
printf("Could not properly load file!\n");
getchar();
getchar();
}
else
{
printf("File opened and loaded properly\n\n");
}
for(i=0;i<28;i+ +)
{
for(j=0;j<28;j+ +)
{
Array[i][j]= ReadFromFile(Ar ray, inFile);
printf("The Array Value at Point %d,%d=%i\n", i+1, j+1, Array[i][j]);
}
fscanf(inFile," \n");
}
fclose(inFile);
getchar();
getchar();
}
int ReadFromFile(in t Array[][30], FILE *inFile)
{
int value;
fscanf(inFile," %i,", &value);
printf("the value=%i\n", value);
return (value);
}
thanks
Comment