#include<iostream> #include<conio.h> #include<stdio.h> void main() { int i; char str[80]; cout<<"enter any name"; gets(str); for(i=0;str[i]!='\0';i++) {cout<<str[i]<<"\n"; } getch(); } | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

#include<iostream> #include<conio.h> #include<stdio.h> void main() { int i; char str[80]; cout<<"enter any name"; gets(str); for(i=0;str[i]!='\0';i++) {cout<<str[i]<<"\n"; } getch(); }

what's wrong in this code?

21st Jun 2016, 12:07 PM
Kshitij
Kshitij - avatar
21 Answers
0
What error do you get?
21st Jun 2016, 12:35 PM
Stefan
Stefan - avatar
0
so many errors like return type should be int in void main() , etc
21st Jun 2016, 12:38 PM
Kshitij
Kshitij - avatar
0
Now I see, you didn't mean compiler errors... It's in many parts not ideal to say the least. It's pretty much C, not C++. There's a potential buffer overflow, the output is not done as easy and straightforward as could be... the input, too.
21st Jun 2016, 12:46 PM
Stefan
Stefan - avatar
0
Welp I figured out that , I need pure c++ like the one we usually have in PC , is turbo c++ the option?
21st Jun 2016, 12:54 PM
Kshitij
Kshitij - avatar
0
Kshitij, what does that mean? Against which compiler are you writing your code? There are so many compilers and language versions that this can be a topic of severe confusion... Pls state name and version and the intended language standard (as modern compilers support C++03, 11, 14 and some features of C++17)
21st Jun 2016, 12:57 PM
Stefan
Stefan - avatar
0
yeah I've guessed something like that. I just need my code to run properly. well I'm a PC user so it's kinda different.I use turbo c++ on PC but as u said its pretty much C so...
21st Jun 2016, 1:06 PM
Kshitij
Kshitij - avatar
0
it's purely beginner code I've written just to check. I thought it would run but oh well XD
21st Jun 2016, 1:08 PM
Kshitij
Kshitij - avatar
0
As you are not stating your compiler I cannot check if any source code I want to suggest compiles on that compiler. I only know Borlands Turbo C++ 3.1 from the time I went to school and wrote my first C++ programs... Anyways, pls tell me how can I help with such an exotic and maybe very outdated compiler?
21st Jun 2016, 1:12 PM
Stefan
Stefan - avatar
0
I'm just using this app to run my program. does the compiler has anything to do what Android OS I'm using? I don't think so
21st Jun 2016, 1:14 PM
Kshitij
Kshitij - avatar
0
So apart from the int return type you do not write "using namespace std;" or prepend "std::" to your "cout". As "cout" is in the namespace "std", the symbol "cout" cannot be resolved. Do one of the suggestions. The better one in my opinion is to prepend "std::"
21st Jun 2016, 1:23 PM
Stefan
Stefan - avatar
0
alright I think I got you. thanks!
21st Jun 2016, 1:33 PM
Kshitij
Kshitij - avatar
0
#include<iostream.h> use it
21st Jun 2016, 1:40 PM
Saurabh Gandhi
0
anyone can you help me? C++ challenge question number 5 can you help me to answer that arrangement.
21st Jun 2016, 1:52 PM
Terence John J. Morilao
Terence John J. Morilao - avatar
0
@Terence John J. Morilao: Pls open a separate thread so others can find your question and may profit from the answers the questions and the answers.
21st Jun 2016, 1:57 PM
Stefan
Stefan - avatar
0
put at the begining: for(int y = 0; y <80;y++) { str[i] = NULL; }
21st Jun 2016, 6:54 PM
Guillem Bartrina
0
i think error may be { }
22nd Jun 2016, 6:07 AM
karthick
karthick - avatar
0
i think....error may be { }
22nd Jun 2016, 6:08 AM
karthick
karthick - avatar
0
rgh
23rd Jun 2016, 3:22 PM
Saúl Blanco Tejero
Saúl Blanco Tejero - avatar
0
write" using namespace std;" after all includes and before void main () change void main to int main and add "return 0;" after getch () and that should do it
25th Jun 2016, 2:45 PM
Mukul Kumar
Mukul Kumar - avatar
0
#include<iostream.h>
8th Nov 2016, 2:34 PM
Soutik
Soutik - avatar