ok im still going on my "read from many files in one function" but with another annoying problem (arent they all annoying!). anyway what i want to do is to read in a word, then increment my passed in counter (it has to be passed cos there is 3 files and 3 arrays to read to, each with different amount of lines).
basically i have no compile errors, but once i 'leave' the function the count does not go into the global variable but just resets to 0 again for the next time.
i think i need to make it equal the global variable or something and not just plus 1 everytime and do nothing to it.
anyway plz have a look.
DECLARATIONS:
FUNCTION CALL:Code:FILE *file = NULL; char comp_street_name[MAX_SIZE][STRING_MAX_SIZE]; char comp_street_type[MAX_SIZE][STRING_MAX_SIZE]; char comp_suburb_name[MAX_SIZE][STRING_MAX_SIZE]; int st_name = 0, st_type = 0, su_name = 0; void readFile(char *read_file, char read_to[][STRING_MAX_SIZE], int count);
FUNCTION:Code:readFile("street_name.txt", comp_street_name, st_name); readFile("suburb_name.txt", comp_suburb_name, su_name); readFile("street_type.txt", comp_street_type, st_type);
any help would be greatly appreciated. thanks in advance.Code:void readFile(char *read_file, char read_to[][STRING_MAX_SIZE], int count) /* Define readFile function */ { /* Start readFile function */ char z = 0; /* Declare temporary read in variable */ int i = 0, j = 0, eof_test = FALSE; /* Declare temporary counting variables */ file = fopen(read_file, "r"); /* Open source file for reading using read parameter */ if(file == NULL) /* Check if read file is corrupted */ { /* Start if statement */ printf("Cannot open input file, please check the filename try again.\n"); /* Print error message */ printf("Input files should be named: street_name.txt, street_type.txt, & suburb_name.txt.\n\n"); /* Print error message */ exit(1); /* Exit due to read file error */ } /* End if statement */ while(eof_test == FALSE) /* Continue read loop while end of file is not found */ { /* Start while loop */ for(i = 0; i < MAX_SIZE; i++) /* Run loop until maximum address book size */ { /* Start for loop */ for (j = 0; j < STRING_MAX_SIZE; j++) /* Run loop until maximum string size */ { /* Start for loop */ z = fgetc(file); /* Gather character from file to temporary variable */ if(z == '\n') /* Check if read in character is the end of line */ { /* Start if statement */ read_to[i][j] = (char) NULL; /* Place null in data array field if end of line */ break; /* Break from for loop for new line */ } /* End if statement */ else if(z == EOF) /* Check if read character is the end of file */ { /* Start if else statement */ eof_test = TRUE; /* Set end of file tester to true */ break; /* Break from for loop if true */ } /* End else if statement */ else /* Else write the read character to data field */ { /* Start else statement */ read_to[i][j] = z; /* Move read in character into array */ } /* End else statement */ } /* End for loop */ if(eof_test == TRUE) /* Check if end of file has been found */ { /* Start if statement */ break; /* Break from for loop if true */ } /* End if statement */ count++; } /* End for loop */ } /* End while loop */ fclose(file); /* Close read in checker file */ }![]()



LinkBack URL
About LinkBacks



