Mega Code Archive

 
Categories / C Tutorial / String
 

Arrays of strings

#include <stdio.h> int main(void) {   char str[][40] =  { "AAA",                       "BBBBBBBB"                     };   int strLength[] = {0, 0};   int i;   for(i = 0 ; i<2 ; i++){     while (str[i][strLength[i]])       strLength[i]++;   }   if(sizeof str[0] < strLength[0] + strLength[1] + 1){     printf("\nNo enough space");   }else{     strLength[1] = 0;     while((str[0][strLength[0]++] = str[1][strLength[1]++]));     printf("\n%s\n", str[0]);   }   return 0; } AAABBBBBBBB