I'm having trouble assigning a character array retued from a function to a variable in main.
char *read(char filename[]) {
int i = 0;
am = 0;
char line[80];
char *record[100];
FILE *infile;
infile = fopen(filename, "r");
while (fgets(line, sizeof line, infile) != NULL) {
record[i] = strdup(line);
i++;
am++;
}
retu record;
}
...
int main() {
char input[100];
char *record[100];
char input2[100];
char input3[100];
while (1) {
scanf("%[^n]%*c", &input);
strcpy(input2, strtok(input, " "));
if (strcmp(input2, "print") == 0){
print(record);
...
else if (strcmp(input2, "read") == 0) {
strcpy(input3, strtok(NULL, " "));
record = read(input3); //input3 is the file name
}
retu 0;
}
I want to take the character array given by "read" and pass it to "print", but I've been unsuccessful. There will be no erroneous input.
