Demonstrate multiple loop control variables : For « Language Basics « C / ANSI-C






Demonstrate multiple loop control variables

Demonstrate multiple loop control variables

#include <stdio.h>
#include <string.h>

void converge(char *targ, char *src);

int main(void)
{
  char target[80] = "This is a test";

  converge(target, "This is a test of converge().");
  printf("Final string: %s\n", target);

  return 0;
} 

/* copies one string into another. 
   It copies characters to both the ends,
   converging at the middle. */
void converge(char *targ, char *src)
{
  int i, j; 

  printf("%s\n", targ);
  for(i = 0, j = strlen(src); i <= j; i++, j--) {
    targ[i] = src[i];
    targ[j] = src[j];
    printf("%s\n", targ);
  }
}

  

           
       








Related examples in the same category

1.For statement: backwards
2.For : no first part
3.For: no init and loop backwards
4.Nested forNested for
5.For loop: List ten integersFor loop: List ten integers
6.For loop: Draw a boxFor loop: Draw a box
7.Use int as the while loop controller
8.Simplest for loop: user control the loop
9.Use for loop as the user selection's controller
10.Use function as for loop control variable
11.For loop without first part
12.For loop without the third part
13.See the for loop terminating condition
14.For loop condition: loop will not execute
15.For loop: bigger increase
16.Prime number tester
17.nested for Demo
18.Use integer as the for loop controller
19.Set the init value for a for loop
20.More calculation in the for statement
21.Simplest for loop
22.Reverse order of for loop
23.Two condition for ending a for loop
24.Three level nested for loop
25.A simple for loopA simple for loop
26.More complex for loop: more statements
27.Infinite for loop with break
28.For loop with init value, stop condition and incr
29.Use char as int in a for loop
30.Nested for loop demo