OK, I have a text file that has "1,2,3 d, e, 6,6, h,h, ...etc" I want to put all the digits into an array for analysis. So the array size known. I am able to open the file and filter the desired digits, but I can't seem to store the numbers into the array properly.
In the array I should see "1,2,3,6,6,..." but I dont. Where did I go wrong?
I got the code to open the file from the development section of this forum.Code:#include <stdio.h> #include <ctype.h> #define ArraySize 40 int ReadDataFromFile(int FileData[ArraySize]); void IntializeArray(int FileData[ArraySize]); int main( void ) { int i; int FileData[ArraySize]; int count=0; IntializeArray(FileData); /*useful data in the array*/ count=ReadDataFromFile(FileData); for(i=0;i<count;i++) printf("%d",FileData[i]); return 0; } void IntializeArray(int FileData[ArraySize]){ int i; for(i=0;i<ArraySize;i++) FileData[i]=1010; }; int ReadDataFromFile(int FileData[ArraySize]){ int i; FILE *fp = fopen( "testdata", "r" ); if ( fp ) { int ch; i=0; while ( ( ch = fgetc( fp ) ) != EOF ) { if(isdigit(ch)){ FileData[i]=ch; i++; } } fclose( fp ); } else { perror( "error opening the file" ); } return i; }