- 1

How to enter a word in CPP in Variable - "char name[20]" ?

In my school and home pc CPP Borland compiler gets(); function is working well but in sololearn learn, it is not working. So can you help me to get a suitable function.

1st Feb 2020, 3:42 AM
Abhay
Abhay - avatar
8 Answers
+ 1
use fgets() instead.
1st Feb 2020, 3:45 AM
Avinesh
Avinesh - avatar
+ 1
It's better if you can share your code here so it is easy to help. Or else the discussion will never end.
1st Feb 2020, 3:48 AM
Avinesh
Avinesh - avatar
+ 1
Your code has a lot of errors and unnecessary lines that will never be accepted in the challenge. Also this is how you use it- fgets(sentence, 200, stdin);
1st Feb 2020, 4:03 AM
Avinesh
Avinesh - avatar
- 1
I had tried but not works
1st Feb 2020, 3:46 AM
Abhay
Abhay - avatar
- 1
What is its header file
1st Feb 2020, 3:46 AM
Abhay
Abhay - avatar
- 1
Ok
1st Feb 2020, 3:49 AM
Abhay
Abhay - avatar
1st Feb 2020, 3:50 AM
Abhay
Abhay - avatar
- 1
#include <iostream> #include<stdlib.h> #include<stdio.h> using namespace std; int main() { system("cls"); char sentence[200],alienS[200]; int i=0,sos; //sos=size of sentence cout<<" Human Language : "; fgets(sentence ); for(sos=1;sentence[sos]!='\0';sos++); for(sos,i;sos>=0;sos--,i++) alienS[i]=sentence[sos]; cout<<"\n\n Alien's Language : "<<alienS; return 0; }
1st Feb 2020, 3:50 AM
Abhay
Abhay - avatar