Hey fellas...
OK, a recent quiz entry tasked the student with writing a method 'longhead' (char *longhead) that would return a string consisting of the concatenation of all of the heads in a given string. Example:
char *string = "this";
printf("%s\n", longhead(string));
OUTPUT: tththithis
I did come up with a solution, but it works with arrays only and it's inside the main method. I've been trying to really get a good foothold on pointers, and I feel that by repeating these quiz questions I'll definitely get to the right place.
Is there a solution to this? Alternatively...could this be done just using 'strlen'?
UPDATE:
Here's the solution I wrote that works with a char array only, and is inside of a main method:
char *toPrint = "roses";
int i, j = strlen(toPrint);
char toPrintArray[j];
for(i = 0; *toPrint != 0; toPrint++, i++){
toPrintArray[i] = *toPrint;
}
int k;
for(i = 0; i < j; i++){
for(k = 0; k < i; k++)
printf("%c", toPrintArray[k]);
}