I got help with this question, and one of the answers suggested this technique, but i keep getting a Segmentation Fault (core dumped) error in this the code.
char *nam = array;//<-----(array is a string, we can use "test string" for it
int i = 0;
int length = strlen(array);
int count = 1;
printf("%i [%s]\n", length,nam);
for(i; i < length; i++)
{
puts(nam + i);
nam[strlen(nam) - 1] = '\0';
}
What's supposed to happen, is I'm supposed to make a pyramid with the string, by removing one letter from the front, and one letter from the back. With this code, I managed to get rid of one letter from the front, but the error occurs on the "replacing" the last letter with a '\0'. Does anyone know why this is happening?
EDIT------------(updated code for clarification)
void pyramid(char array[])
{
char nam[] = array;
int i = 0;
int length = strlen(nam);
int count = 1;
printf("%i [%s]\n", length, nam);
for(i; i < length; i++)
{
puts(nam + i);
nam[strlen(nam) - 1] = '\0';
printf("[%s]\n", nam);
}
}
main class
int main (void)
{
char *name = "TEST STRING";
pyramid(name);
}
hope this clarifies this code gives me an invalid initializer on the char[] = array; line