+ 1

taking input from user | C

I am trying to use gets and scanf functions but where am i doing wrong? #include <stdio.h> int main() { int age; char name[25], hometown[15]; printf("What\'s your name: \n" ); gets(name); printf("Where are you from: \n"); gets(hometown); printf("How old are you: \n"); scanf("%d", &age); printf("Welcome to %d club, ", age); printf("%s", name); printf(" from %s! ", hometown); getch(); return 0; }

12th Oct 2019, 12:37 PM
volfr
volfr - avatar
4 Antworten
+ 3
Can you tell me why you created an array for the <age> variable? your code will execute if you use a regular int variable rather than an array of int.
12th Oct 2019, 1:28 PM
Ipang
+ 3
check here give input like this in separate line name hometown age https://code.sololearn.com/cbBD3ZAGs1xy/?ref=app
12th Oct 2019, 1:27 PM
Programmer Raja
Programmer Raja - avatar
+ 2
thanks for the answers, I don't know why I did this 😂 I guess I was just trying something and forgot to delete it. Anyways thanks 💕
12th Oct 2019, 1:33 PM
volfr
volfr - avatar
+ 1
volfr Please don't mark my response, it was a confirmation rather than an answer. Mark a response which provides a solution that you found to be helpful 👍
12th Oct 2019, 3:12 PM
Ipang