I encountered this problem when going over some walkthrough's.
Code:
for (i = 1; i + k < len; i++)
{
for (j = i; s[j + k]; j++)
s[j] = s[j + k];
s[j] = '\0';
len -= k;
k++;
}
In the nested for loop,
Code:
for (j = i; s[j + k]; j++)
what does s[j + k] do? how does the for loop terminate? assume s is an array of characters.
Any help would be great. Thanks
Here's the whole program:
Code:
#include <stdio.h>
#include <string.h>
void fold(char s[], int k)
{
int i, j, len;
len = strlen(s);
for (i = 1; i + k < len; i++)
{
for (j = i; s[j + k]; j++)
{
s[j] = s[j + k];
}
s[j] = '\0';
len -= k;
k++;
}
}
main()
{
char s1[31], s2[31];
strcpy(s1, "Show me less!? We always");
strcpy(s2, "worry:kiss and neck, or split");
fold(s1, 1);
fold(s2, 0);
printf("%s %s all, however\n", s1, s2);
}
Output:
Some ways work not all, however