The following segment of code is generating a segmentation f
Solution
1)at the comarision the problem is occuring
2) if sufficient memory is not allocated at the runtime for the resultant variable segmentation problem will occur
3)I just allocated the memory at runtime
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* run this program using the console pauser or add your own getch, system(\"pause\") or input loop */
char *combineStrings(char* string1,char *string2){
char* returnString;
if((string1!=NULL)&&(string2!=NULL)){
returnString = malloc(strlen(string1)+1+4);
strcpy(returnString,string1);
strcat(returnString,string2);
}
return returnString;
}
int main(int argc, char *argv[]) {
printf(\"String Operations:\ \");
char* string1 = \"Your \";
char* string2= \"Friend\";
char* result =combineStrings(string1,string2);
printf(\"%s\",result);
return 0;
}
