I try to make a function that gets a string delivered like "Hello". The function's return value should be an array of strings that would look like
H
He
Hel
Hell
Hello
I really don't know how to do that. My current code is super messy because I made a lot of adjustions and everyone made it worse.
char stutterString(char string[])
{
rowLength = strlen(string);
char help_string[][rowLength]; // I wanted to make the onedimensiol string i get into a two dimensial one so I can then compare my strings in a forloop
strcpy(help_strig, string); // I'm not sure if that's how you copy a 1d string into a 2d string, I guess not.
My loops look like
for(; count1 <= COLUMN; count1++)
{
for(count2 = 0; count2 <= NumberRow; count2++)
{
new_string[count1][ROW] = help_string[0][count2];
ROW++
}
NumberRow++;
}
// NumberRow indicates the limit on the letters that should be copied. like in the beginning it's 1 for H, then 2 for the He and so on..
//count1 is for the column number we r currently and count2 for the row
Any ideas how I could achieve that easier / where to improve my code?
char help_string[][rowLength];is illegal, as isstrcpy(help_strig, string);. Also it's not possible to return an array of strings in C. I'd suggest reading some tutorials or books about arrays, before continuing