What is alternative of cin.ignore(); (used in C++) in C | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

What is alternative of cin.ignore(); (used in C++) in C

#include <stdio.h> int main() { char ch,s[100],sen[200]; scanf("%c",&ch);//to input a character scanf("%s",&s);//to input a string gets(sen);//to input a sentence printf("%c\n",ch);//to print character printf("%s\n",s);//to print string printf("%s",sen);//to print sentence return 0; } In this Code memory of sen remains empty i.e value inputed for sen is not being stored in it. So what can be done to store it. As scanf("%s", &sen); terminates on pressing space or enter

10th Oct 2019, 8:35 PM
Mayank Matwa
3 Answers
+ 4
Thanks for your review Omkar But the space after format specifier also terminates as the space appears. I think I found an Alerternative of cin.ignore() in C checkout here : https://code.sololearn.com/coQZZxSUAMLJ/?ref=app
11th Oct 2019, 8:45 PM
Mayank Matwa
+ 3
Mayank Matwa Nice solution. However using space will also work. You may have misplaced space. You should give space between ending quote and 's' of format specifier scanf("%s ",s); //one more thing that you don't need a & because array name itself is pointer to first element.
12th Oct 2019, 12:56 AM
🇮🇳Omkar🕉
🇮🇳Omkar🕉 - avatar
+ 2
Mayank Matwa There is no alternative for cin.ignore(); in C according to SO discussion: https://stackoverflow.com/questions/53037333/whats-the-equivalent-of-cin-ignore-in-c But using a space after format specifier will solve the problem. scanf("%s ",s);// see the space after format specifier
10th Oct 2019, 10:14 PM
🇮🇳Omkar🕉
🇮🇳Omkar🕉 - avatar