+ 1

When I enter the first input, the program breaks and prints 0

https://code.sololearn.com/cmh34quBUI9Z/?ref=app

15th Aug 2019, 6:25 PM
Geek
Geek - avatar
11 Antworten
+ 3
~ swim ~ Didn't knew we can read spaces like that from scanf. I always used gets or fgets for that. Thanks for telling me about it.
15th Aug 2019, 7:26 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 2
Geek you are doing first scanf wrongly...it should be as below and you are done : scanf("%[^\n] ",a); scanf require memory address to store input value and a is already array which don't need to be passed as &a as it means double pointer instead of single pointer... for char x, you can pass &x..for int g, you can pass &g and so on but for array , you should pass directly array... next point was to have format as %[^\n]s... it means you expect two input... one for %[^/n] and other for s... %[^/n] itself take care of input string with space
15th Aug 2019, 7:23 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
+ 1
~ swim ~ Why &a is wrong in first scanf?? We can take input as a string using scanf
15th Aug 2019, 7:28 PM
Alaska
Alaska - avatar
+ 1
Ohhk I got it..But one thing i want to ask what happens in memory if we use &a..I mean a has address of first element and if we use &a it will be address of(address of first element)..
15th Aug 2019, 7:36 PM
Alaska
Alaska - avatar
+ 1
~ swim ~ Got it!! Thanks
15th Aug 2019, 7:46 PM
Alaska
Alaska - avatar
+ 1
Thanks for your help. Because of you only, I am learning new things. Will require more help like this to learn more. Thankyou again!
15th Aug 2019, 8:09 PM
Geek
Geek - avatar