Arrays of strings


Levels of difficulty: / perform operation:


Program

#include <stdio.h>

int main(void)
{
  char str[][40] =  { "asdf",
                      "fdsa"
                    };
  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;
}


Result

asdffdsa





Quantitative Aptitude
Reasoning
Programming
Interview