#include <stdlib.h> #include <stdio.h> #define STR_SIZE1 1024 #define STR_SIZE2 1024 char StrCat(char *f,char *s) { char *ptr1,*ptr2; char array1,array2; ptr1 = &f; array1 = *f; ptr2 = &s; array2 = *s; return array1,array2; } int main() { char first[STR_SIZE1]; char second[STR_SIZE2]; printf("Please enter first string: "); scanf("%s", first); printf("Please enter second string: "); scanf("%s", second); printf("%s%s",StrCat(second,first)); return 0; } 

The code is compiled, but after entering the lines, the program crashes. Tell me, what could be the error and what should be corrected?

  • uh ... and who taught you to use the operator comma? PS you can remove the function call and printf("%s%s",second,first); and everything - pavel
  • I would very much like to hear what you think your Strcat() code Strcat() ... - Harry
  • Sadly, the answer to your previous question has not taught you anything. You persist in trying to do something with strings, just by playing pointers to them. C is very different from most other languages ​​by the fact that you can directly access memory here. This is a huge plus. But of course a big minus, for those who are not aware of how the processor and memory work. A string is a set of bytes in memory and in C in order to do something with a string, you must loop around each of these bytes and do something with it. - Mike

1 answer 1

Pancake...

 char * s1 = first; char * s2 = second; for(;*s1;++s1); while(*s1++ = *s2++); 

Like that. If only in the first place there is enough for second ...