Discussion Locked

C PROGRAM CORRECTION

0 helpful
11 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

HI!

I HAVE WRITTEN A SIMPLE PROGRAM IN 'C', ALL IT HAS TO DO IS DISPLAY THE FIRST COMMAND LINE PARAMETER..

MY CODE IS

# include

int main(int argc, char *argv[])
{
printf("hello %s", argv[0]);
getch(); }

THE ERROR I GET WHILE COMPIPLING IS..

d:\cprog\j_first: 49,52: Parse Error, expecting `')'' or `',''
'main(int argc,char *argv[]) { printf("hello %s", argv[0])'

PLEASE HELP.
THANK YOU

11 replies

by hasse mcse/brainbench

Hi!

I can't find anything wrong in your code except theese things:

# include

int main(int argc, char *argv[])
{
printf("Param #1: %s\n", argv[1]);
}

This is a better program and this works, if you can't compile the above something is wrong with your compiler.

/Hasse

by pvp

Is that really a space between '#' and "include"?

Should be "#include" starting in column 1.

by cedric king

Could the problem lies in your stdio.h?
A common mistake could be that in between your int Main and your "{" is not a hard break. Check that it's a hard break cos if there's error, it should not show both the lines unless they belong to the same line.

by shane

Hi,
It appears that you have left the closing parenthesis - ')' out of the int main line.
(not in your post here but in your code).
Did you cut and paste? or retype it here in your post?

by basilisk

Does that 49,52 refer to line numbers? (Most compilers take a guess at which line has the problem.) Then you need to check your file for hidden characters; this simple a program shouldn't have that many lines. Also, it looks like your filename forthe source code has no extension. Check your compiler; some require an extension like .c or .cpp in order to compile in the correct language.

This discussion is closed to new replies.