English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

#include "stdafx.h

int main(int argc, char* argv[])
{
int c;

c = getchar();
while (c != EOF) {
putchar(c);
c = getchar();
}
}


That is my code. when I run it, it shows an error. I use Microsoft Visual C++, Windows XP, and I am making a Console Application. A little help please...

2006-07-10 12:07:58 · 6 answers · asked by dwzigzag 2 in Computers & Internet Programming & Design

Guy's, I've fixed it. I'll choose a best answer though...

2006-07-10 13:51:03 · update #1

6 answers

you are missing a closing quote on the include

#include "stdafx.h"

2006-07-10 12:10:32 · answer #1 · answered by Bors 4 · 4 0

getchar(); is an undeclared identifier. What do you want to do with getchar(); ? What will getchar be? A number, a letter, a string, what? Identify it. Just like int c; you need to indentify getchar(); - Without quotations it becomes a variable, but the variable is undeclared. When in doubt, find out what type of program you are making and look for it on the internet. You can find alot of C++ programming examples. Just type around. You'll find the answer. In C++, one error leads to another. Tip: Build your application after each line of code so that you may find your errors as you go along. Instead you are writing a program with errors from the start. When you fix one error, another will pop up. Start over and build from beginning. Don't just code away.

2006-07-10 20:01:54 · answer #2 · answered by john s 1 · 0 0

I think you selected the wrong options while creating your project.

Why don't you try creating a new project and then copy and paste your main into the new project, and then try running it. ( and add the header )

The steps for creating a project are:
-New Project
-select C++ , win 32 on left side and Win 32 Console project on the right side
-select location where to create , give name
-select Application Settings, click on Console and Empty,
-Finish



Oh, and another thing is that you don't have a return statement in your main. You always need to have a return statement in your main function!!!! Since, you said int main, your main should return an integer and so you could put something like a return 0; as the last statement in your main.

Hope this fixes your problem.

2006-07-10 19:55:36 · answer #3 · answered by M 1 · 0 0

You are missing a closing speech mark (") on your first line, so C thinks your whole file is part of the filename to include! (You are probably getting an EOF error).

Maybe this is more what you want (I'm assuming your header file stdafx.h contains the standard input/output library stdio.h):

---

#include

int main(int argc, char* argv[])
{
int c;

while ( (c=getchar()) != EOF) {
putchar(c);
}

return 0;
}

---

You might also find this website useful (I do):
http://www.cppreference.com/index.html

2006-07-10 19:24:14 · answer #4 · answered by Fru. T Bunn 2 · 0 0

! = i think

see what happens...

if not take the damn P.C. back to the shop and tell them you are to thick to own a p.c.!

LoL! I wish you luck... i have not got a clue... cheers!

I guess you got Cods Heads there! hope these kind people help!

2006-07-10 19:14:51 · answer #5 · answered by AZRAEL Ψ 5 · 0 0

lets see my answer is....................... get a life

2006-07-10 19:11:14 · answer #6 · answered by unknown 3 · 0 0

fedest.com, questions and answers