Mega Code Archive

 
Categories / C / Code Snippets
 

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 testing"; converge(target, "This is a test of converge()."); printf("converge done 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 k, j; printf("%s\n", targ); for(k = 0, j = strlen(src); k <= j; k++, j--) { targ[k] = src[k]; targ[j] = src[j]; printf("%s\n", targ); } }