Find Error : | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Find Error :

What's the error in my code. I want to take multiple name from user but this program is not taking the first name. #include<stdio.h> #include<string.h> char * find(char str[]) { return str; } int main() { int t,j; printf("Enter number of loops : "); scanf("%d",&t); for(j=1; j<=t; j++) { char str[100]; printf("Enter name %d :",j); gets(str); printf("%s\n",find(str)); } return 0; }

3rd Jan 2021, 7:11 PM
Samir Singh
Samir Singh - avatar
2 Answers
+ 1
Try reading the name using `fgets` or `scanf` instead of `gets`. `gets` is deprecated and will be removed from C standards soon (if not already). fgets( str, 100, stdin ); Or scanf( "%99[^\n]", str );
3rd Jan 2021, 7:29 PM
Ipang
0
%d is for double format but you use it for string .correct is %s
3rd Jan 2021, 7:15 PM
HBhZ_C
HBhZ_C - avatar