C examples for String:char array
Copies the contents of one string into another by moving characters from both ends, converging in the middle with multiple loop control variables
#include <stdio.h> #include <string.h> void converge(char *targ, char *src); int main(void) { char target[80] = "-----------------------------"; converge(target, "This is a test of converge ()."); printf("Final string: %s\n", target); return 0;//from w ww . j a v a2s. c o m } /* This function 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); } }