why I am unable to run the scanf() function in c? | SoloLearn: Learn to code for FREE!

+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.

c

5/7/2021 3:57:31 PM

Archit Kar

15 Answers

New Answer

+6

Hey Archit Kar Use address-of operator (&) to store variable ! Ex: scanf("%c",&firstname);

+4

You need to store the name in an array of chars.

+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

+2

Show your code to find error and help you with perfect solution👍

+1

it does, please post your code

+1

Using sololearn app? 😢

+1

correct, what output did you expect?

+1

ok thanks

+1

include header file... #include<stdio.h>

+1

If still it's not working plzz send the codes!!

+1

The declaration... char firstname; declares a single character variable. The declaration... char firstname[]; declares an array of characters of zero size. In other words a pointer to nothing. For information on how to use scanf see: https://www.cplusplus.com/reference/cstdio/scanf/ #include <stdio.h> int main () { char firstname[80]; printf ("Enter your first name: "); scanf ("%79s", firstname); printf ("Hello %s.\n", firstname); return 0; }

+1

thnx bro

0

my code is:- char firstname; printf("what is your name? \n"); scanf("%s", firstname); but the output is coming. what is your name?

0

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);

0

used may not used the library function stdio.h