why I am unable to run the scanf() function in c? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

why I am unable to run the scanf() function in c?

it is not running in the c programming language. I am unable to understant how so plzz tell me about that.

7th May 2021, 3:57 PM
Archit Kar
14 Answers
+ 6
Hey Archit Kar Use address-of operator (&) to store variable ! Ex: scanf("%c",&firstname);
7th May 2021, 5:05 PM
Giriraj Yalpalwar
Giriraj Yalpalwar - avatar
+ 4
You need to store the name in an array of chars.
7th May 2021, 4:38 PM
Arturop
Arturop - avatar
+ 3
Mahmoud 'Carbon' Saghraoui are you sure about that char[] declaration? I think it has to have fixed size, so you must declare size of that array, or make char pointer to allocate memory dynamically
7th May 2021, 5:20 PM
Michal Doruch
+ 2
Show your code to find error and help you with perfect solution👍
8th May 2021, 10:24 AM
Gaurav Dixit🇮🇳
Gaurav Dixit🇮🇳 - avatar
+ 1
it does, please post your code
7th May 2021, 4:04 PM
Slick
Slick - avatar
+ 1
Using sololearn app? 😢
7th May 2021, 4:31 PM
Arturop
Arturop - avatar
+ 1
correct, what output did you expect?
7th May 2021, 4:32 PM
Slick
Slick - avatar
+ 1
I don't see any mistakes there, you may not understand your own code so let me explain it for you. ----------------------------- char firstname[]; <-- Declared a variable, i've added the '[]' keep 'em printf("what is your name? \n"); <-- This prints 'what is your name' scanf("%s", firstname); <-- Takes the input of the server ----------------------------- If you want to print the name after the input was taken then you can do printf("Your first name is: %s", firstname);
7th May 2021, 4:42 PM
Carbon
Carbon - avatar
+ 1
ok thanks
7th May 2021, 4:54 PM
Archit Kar
+ 1
include header file... #include<stdio.h>
7th May 2021, 5:28 PM
#niNja_coder
#niNja_coder - avatar
+ 1
If still it's not working plzz send the codes!!
7th May 2021, 5:29 PM
#niNja_coder
#niNja_coder - avatar
+ 1
thnx bro
8th May 2021, 6:04 AM
Archit Kar
0
my code is:- char firstname; printf("what is your name? \n"); scanf("%s", firstname); but the output is coming. what is your name?
7th May 2021, 4:08 PM
Archit Kar
0
used may not used the library function stdio.h
9th May 2021, 4:48 AM
Gaurav Kumar
Gaurav Kumar - avatar