Hello guys, I'm new to c programming. I came across a problem when I go through a String tutorial.
Attachment 1 is and Attachment 2 shows the program and results when I run the program.
Both program are just different by StrA[] and StrA[20].
When i run the 1st program, the results that i expected is not displayed (String5).
Can anyone help me about it?
1st program
#include <stdlib.h>
#include <string.h>
void main()
{
int strLENGTH = 0;
char strA[20] = "OPC";
char strB[20] = "World";
printf("String1 = %s \n",strA);
printf("String2 = %s \n",strB);
strLENGTH = strlen(strA);
printf("StringLength1 = %d \n",strLENGTH);
printf("String3 = %s \n",strA);
printf("String4 = %s \n",strB);
strcat(strA,strB);
strLENGTH = strlen(strA);
printf("StringLength2 = %d \n",strLENGTH);
printf("String5 = %s \n",strA);
printf("String6 = %s \n",strB);
}
2nd program
#include <stdlib.h>
#include <string.h>
void main()
{
int strLENGTH = 0;
char strA[20] = "OPC";
char strB[20] = "World";
printf("String1 = %s \n",strA);
printf("String2 = %s \n",strB);
strLENGTH = strlen(strA);
printf("StringLength1 = %d \n",strLENGTH);
printf("String3 = %s \n",strA);
printf("String4 = %s \n",strB);
strcat(strA,strB);
strLENGTH = strlen(strA);
printf("StringLength2 = %d \n",strLENGTH);
printf("String5 = %s \n",strA);
printf("String6 = %s \n",strB);
}