User forums > Using Code::Blocks
Different between StrA[] and StrA[20]
(1/1)
yw sea:
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?
--- Code: ---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);
}
--- End code ---
--- Code: ---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);
}
--- End code ---
Miguel Gimenez:
Your question is off-topic in this forum, you should ask in a C-programming forum or read a book.
yw sea:
Noted with thanks
Navigation
[0] Message Index
Go to full version