+ 7

Whats the error here?

I cant find the error https://code.sololearn.com/c4Oy1zF4u2KY/?ref=app

24th Dec 2019, 4:32 PM
Y AD Ù
Y AD Ù - avatar
21 Respostas
+ 4
Y Åđ Û Randych You need to give inputs in two separate lines. Because gets reads entire line. So give inputs like ex: Scanner n Output: 2 To use fgets, write fgets(string, 20,stdin);
24th Dec 2019, 5:01 PM
Jayakrishna 🇮🇳
+ 2
Kindly avoid using gets() because it is not recommended for certain reasons that you can read by yourself online. You can use fgets(). The code is giving the result you expected. It is counting the number of characters present in the string matching the key.
24th Dec 2019, 4:56 PM
Avinesh
Avinesh - avatar
+ 2
Tnks guys i got it
24th Dec 2019, 5:12 PM
Y AD Ù
Y AD Ù - avatar
+ 2
Instead of using built in function you can define one self according to your need For.eg. If you want to only input a to z for(int i=0,c = getchar(); i<size; c = getchar() ) { if(c <= 'a' && c >= 'z') string[i++] = c; else break; }
25th Dec 2019, 4:33 PM
Sp Maurya
Sp Maurya - avatar
+ 2
In the input first enter string And in the next line enter key character
25th Dec 2019, 5:50 PM
Narra Ajay
+ 2
But there is no error! It is working quite fine. P. S. Don't forget that the fgets includes the terminating return character in the string too. It shouldn't cause any problem here though. :)
26th Dec 2019, 8:57 AM
Param Siddharth
Param Siddharth - avatar
+ 1
I failed to understand what you were trying to achieve.
24th Dec 2019, 4:38 PM
Randych
Randych - avatar
+ 1
Nothing. Working fine. Are you not getting the output? But it's better to fgets instead gets();
24th Dec 2019, 4:49 PM
Jayakrishna 🇮🇳
+ 1
Jayakrishna it appears the output isn't what he's expecting.
24th Dec 2019, 4:53 PM
Randych
Randych - avatar
+ 1
Randych Y Åđ Û What inputs you are giving,? What is expected output? How you giving the outputs?
24th Dec 2019, 4:55 PM
Jayakrishna 🇮🇳
+ 1
Y Åđ Û see Jayakrishna has mentioned it in the last line.
24th Dec 2019, 5:07 PM
Avinesh
Avinesh - avatar
+ 1
Y Åđ Û well then show how you've changed the code
24th Dec 2019, 5:09 PM
Randych
Randych - avatar
+ 1
Isn't it right🤔 it gives ans
25th Dec 2019, 10:56 AM
Ruchita Oza
+ 1
It's fine just you need write in two lines: barca a Output: barca has 2 a in it.
26th Dec 2019, 5:06 AM
Marco
Marco - avatar
+ 1
Hallo
26th Dec 2019, 3:28 PM
Indra Lucmana II
Indra Lucmana II - avatar
0
I was trying to enter a string...and then enter a character to find its frequency in that particular string
24th Dec 2019, 4:47 PM
Y AD Ù
Y AD Ù - avatar
0
Jayakrishna yea that's what confused me
24th Dec 2019, 5:02 PM
Randych
Randych - avatar
0
Avinesh bruh..wen i use fgets(strimg) Its not working :/
24th Dec 2019, 5:04 PM
Y AD Ù
Y AD Ù - avatar
0
Ruchita Oza i have changed it and made it right
25th Dec 2019, 11:19 AM
Y AD Ù
Y AD Ù - avatar
0
Privet
25th Dec 2019, 4:40 PM
sherzod