Novice C language learning journey(6)
This code will shows a strange output when run it.Why?
Look at the "strcat" function and "puts" function.These function need string variable.But "getchar" function read a character only,lacking '\0' character.The char array of "a,b,c" did not initialization.So the input is not a string.The variable type is not match.The code as follows:
#include"stdio.h"
#include"stdlib.h"
int main(void){
char a[23];
char b[33];
char c[22];
a[0]=getchar();
b[0]=getchar();
c[0]=getchar();
strcat(a,b);
strcat(a,c);
puts(a);
puts(b);
puts(c);
return 0;
}
The modified as follows:
#include"stdio.h"
#include"stdlib.h"
int main(void){
char a[23]="qwe";
char b[33]="rty";
char c[22]="uio";
a[0]=getchar();
b[0]=getchar();
c[0]=getchar();
strcat(a,b);
strcat(a,c);
puts(a);
puts(b);
puts(c);
return 0;
}
Welcome to steemit @sky-999.
Welcome the new steemians. Have a great day!
Congratulations @sky-999! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :
You can view your badges on your Steem Board and compare to others on the Steem Ranking
If you no longer want to receive notifications, reply to this comment with the word
STOP
To support your work, I also upvoted your post!
Do not miss the last post from @steemitboard:
Vote for @Steemitboard as a witness to get one more award and increased upvotes!
According to the Bible, Charity Means Love (5 of 5)
(Sorry for sending this comment. We are not looking for our self profit, our intentions is to preach the words of God in any means possible.)
Comment what you understand of our Youtube Video to receive our full votes. We have 30,000 #SteemPower. It's our little way to Thank you, our beloved friend.
Check our Discord Chat
Join our Official Community: https://beta.steemit.com/trending/hive-182074
Hey sky-999! If you would like to make your personal feed contain the top trending media and talking points of the whole internet, consider following @coffeebreak and @topicstoday accounts - And welcome to Steem!