+ 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; }
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 );
0
%d is for double format but you use it for string .correct is %s