2d array, using calloc in C
- by BigBirdy
Hi,
I'm trying to create a 2D array of chars to storage lines of chars. For Example:
lines[0]="Hello";
lines[1]="Your Back";
lines[2]="Bye";
Since lines has to be dynamically cause i don't know how many lines i need at first. Here is the code i have:
int i;
char **lines= (char**) calloc(size, sizeof(char*));
for ( i = 0; i < size; i++ ){
lines[i] = (char*) calloc(200, sizeof(char));
}
for ( i = 0; i < size; i++ ){
free(lines[i]);
}
free(lines);
I know that each line can't go over 200 chars. I keep getting errors like "error C2059: syntax error : 'for'" and such. Any ideas of what i did wrong?