I have written this code to read in a CSV file. It is compiling fine, but the a.out file is telling me the file does not exist. I have double checked file name and location but all seems in order. Am I doing something wrong with the code itself?
The code goes on after this, I know the main function isn't closed.Code:int main ( void ) { /*file type warning*/ printf ("Please make sure the file is in CSV format before continuing.\n"); /*ask for file name */ char filename [128] ; fputs ("Enter the filename: ", stdout) ; fflush(stdout) ; fgets(filename, sizeof filename, stdin ) ; /*create file pointer*/ FILE *fp ; /*open file*/ fp = fopen (filename, "r") ; int row, column ; /*read file*/ char arra [6] [2000] ; char line [2000]; for( row = 0; row < 5; row++ ) for( column = 0; column < 2000; column++ ) arra [row] [column] = '\0' ; for (row = 0; row < 5; row++) line [row] = '\0' ; if ( fp != NULL) { row = 0 ; while (fgets (line, sizeof line, fp ) != NULL) /*read a line*/ { strcpy (arra[row], line) ; printf ("array --> %s", &arra[row]) ; row++; } fclose(fp) ; } else { perror( filename) ; }



LinkBack URL
About LinkBacks


