>>>>mystrings[Charcount]
O.K., this is an array of chars.
mystrings[Linecount][Charcount]
This is an array of strings, each one being "Charcount" long
So first count newlines, like I said before.
Then loop again to find the max number of chars in each string. Like this:
PHP Code:
int len=strlen(string);
char newline='\n'; //stop counting char at a '/0' too...
int count_max=0;
int max_sz=0;
for(int d=0;d<len;d++)
{
if(isalpha(string[d]) || isdigit(string[d]) || isspace(string[d]) && string[d] != newline)
{
count_max++;
if(count_max > max_sz)
{
max_sz=count_max;
}
}
else {
count_max=0; // reset to count the others
}
}
'max_sz' is now the length of your longest string.
Now, assuming you have figured out how to count your newlines, let's just call the number of newlines "max_num". So now we create and initialize the array of strings.
PHP Code:
char line[max_num][max_sz+3]; //+3 for safety
for(int h=0; h<=max_num-1; h++) //-1 because arrays start @ '0'
{
fgets(line[h],max_sz+2,string); //+2 for safety
}
Voila! An array of strings. Simple,huh?
But that's just the beginning. Now you have to pull the data from them!
To make an array of pointers to those strings you would simply do:
PHP Code:
char *line_ptrs[max_num];
for(int y =0; y<=max_num-1; y++){ line_ptrs[y] = line[y]; }