Novice C language learning journey(5)

in #art5 years ago

梦幻光晕蓝色背景矢量图.png
This code has a error when run it,the compiler shows "[Warning] return makes integer from pointer without a cast".
Why it shows this error?
The "world" function is char type.So the return type must be char type.But the formal parameter of "world" function is "char*" type.
So the type is not match.The code as follows:

#include"stdio.h"
char world(char name[5]){
strcpy(name,"abs");
printf("%s",name);
return(name);
}
int main(void){
char a[12];
world(a);
return 0;
}
捕获.PNG
So how to modify?
the solution as follows:

#include"stdio.h"
char* world(char name[5]){
strcpy(name,"abs");
printf("%s",name);
return(name);
}
int main(void){
char a[12];
world(a);
return 0;
}
捕获45.PNG

Sort:  

Congratulations @sky-999! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

You made more than 10 comments. Your next target is to reach 50 comments.
You got more than 10 replies. Your next target is to reach 50 replies.

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

Do not miss the last post from @steemitboard:

Valentine's day challenge - Give a badge to your beloved!
Vote for @Steemitboard as a witness to get one more award and increased upvotes!