1. ## For Loop Question

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

2. Here's how I "read" for loops:
Code:
```int n;
for (n = 0; n < 100; n++)
...```
"For n equals 0, while n is less than 100, n plus plus"
The first expression is only executed once, and first: "n = 0".
The middle expression is the loop conditional - while expression is true, keep truck'n
The last expression is executed after every loop and before the middle expression is executed.

So we can rewrite the loop as while loop like so:
Code:
```int n = 0;
while (n < 100)
{
...
n++;
}```
A conditional expression is C will evaluate to true (non-zero) or false (zero). So if s[j + k] contains a value of 0, then "if (s[j + k])" will evaluate to false.
0 == '\0'

gg

3. >>main()
That's wrong, main() only returns integer, so you should change this to int main() and at the end of the program return a value;

4. >That's wrong
Only half wrong. With C89 if the return type is omitted then int is assumed, C99 makes this illegal though. Another interesting property of the implicit int is that by using it if you don't actually return a value, the compiler tends not to complain. I believe this is why such declarations of main were popular. But to be 100% correct and portable, main should be declared as so:
Code:
```int main ( void )
{
return 0; /* May be omitted in C99, 0 returned by default */
}```
or
Code:
```int main ( int argc, char *argv[] )
{
return 0; /* May be omitted in C99, 0 returned by default */
}```
Other portable return values are defined as EXIT_SUCCESS and EXIT_FAILURE in stdlib.h.

-Prelude