Question: Read multiple text files line by line into an array of strings in C int main(int argc , char **argv) { char Memory[argc - 1][512][8];
Read multiple text files line by line into an array of strings in C
int main(int argc , char **argv) {
char Memory[argc - 1][512][8]; // int Time_Quantum; // int ProgNum = 1;
do { for(int i = 1; i < argc; i++) { FILE *f = fopen(argv[i], "r"); if (f == NULL){ printf("Failed! Please check the location or spelling of the file: \"%s\" " , argv[i]); return 1; }
//Limited to 6 Lines for the sake of troubleshooting for(int j = 0; j <= 6; j++) { printf("%s" , Memory[i][j]); //Places each line in the file into the current open program's fgets(Memory[i][j] , sizeof(Memory[i][j]) , f); //Removes ' ' character at the end of each line in the file // char *pos; // if ((pos=strchr(Memory[i][j], ' ')) != NULL) // *pos = '\0'; //Prints lines of program for troubleshooting purposes printf("%s " , Memory[i][j]); } fclose(f); }
ProgNum++;
}while(ProgNum != argc);
I thought the array was going to be produced as described below but I'm having trouble with the output
Memory[File to be read in][line of the file][size of each line]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
