I know a string is just an array of chars, but how can I make an array of strings?
Code:
#include <stdio.h>
#define length 80
void main(void) {
FILE *fp;
int ch;
char *str;
int i=0;
if ((fp=fopen("myfile.txt","r")) == NULL) {
printf(stderr,"fopen: Error opening file\n");
exit(1);
}
while (!feof(fp)) {
fgets(str, length, fp);
printf("%s",str);
fflush(str);
}
fclose(fp);
exit(0);
}
The above prints out the each line like it's supposed to, now if I try this:
Code:
char *str[10];
.................................................
while (!feof(fp)) {
fgets(str[i], length, fp);
printf("%s",str[i]);
fflush(str[i]);
i++;
}
I get segmentation faults. The purpose is not actually to print the lines, but to actually manipulate them first and then print to the screen which is why an array would help. Any suggestions? Thanks.