Strings continued
There are times that the length of a
string may not be known. Consider the following improvements
by terminating each string with a null character.
#include <stdio.h> main() { static char string1[] = "Bye Bye "; static char string2[] = "love."; char string3[25]; int n = 0, n2; for( ; string1[n] != '\0'; ++n ) string3[n] = string1[n]; n2 = n; n = 0; for( ; string2[n] != '\0'; ++n ) string3[n2 + n] = string2[n]; n2 += n; for(n = 0; n < n2 ; ++n) printf("%c", string3[n]); }
Minor modification to above program is, string3[n2 + n] = '\0'; printf("%s", string3);
©Copyright B Brown. 1984-1999. All rights reserved.