I expect to have OmelianLevkovych.
The following code snippet:
#include <stdio.h>
#include <stdlib.h>
const char* GetFullName(char firstName[], char lastName[])
{
return strcat(firstName, lastName);
}
int main()
{
char firstName[] = "Omelian";
char lastName[] = "Levkovych";
char* fullName;
fullName = GetFullName(firstName, lastName);
printf("%s", fullName);
return 0;
}
I am using Code.Block IDE 20.03 (default hello-world template proj).
CodePudding user response:
You dont have enough space allocated in the string firstname. Strcat appends lastname to firstname string and returns a pointer to firstname string.
The quick fix would be :
char firstName[30] = "Omelian";