General discussion

Locked

C PROGRAM CORRECTION

By john_bosko ·
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 <stdio.h>

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

This conversation is currently closed to new comments.

11 total posts (Page 1 of 2)   01 | 02   Next
| Thread display: Collapse - | Expand +

All Comments

Collapse -

C PROGRAM CORRECTION

by Hasse MCSE/Brainbench In reply to C PROGRAM CORRECTION

Hi!

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

# include <stdio.h>

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

Collapse -

C PROGRAM CORRECTION

by john_bosko In reply to C PROGRAM CORRECTION

Poster rated this answer

Collapse -

C PROGRAM CORRECTION

by pVp In reply to C PROGRAM CORRECTION

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

Should be "#include" starting in column 1.

Collapse -

C PROGRAM CORRECTION

by john_bosko In reply to C PROGRAM CORRECTION

Poster rated this answer

Collapse -

C PROGRAM CORRECTION

by Cedric King In reply to C PROGRAM CORRECTION

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.

Collapse -

C PROGRAM CORRECTION

by john_bosko In reply to C PROGRAM CORRECTION

Poster rated this answer

Collapse -

C PROGRAM CORRECTION

by shane In reply to C PROGRAM CORRECTION

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?

Collapse -

C PROGRAM CORRECTION

by john_bosko In reply to C PROGRAM CORRECTION

Poster rated this answer

Collapse -

C PROGRAM CORRECTION

by basilisk In reply to C PROGRAM CORRECTION

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.

Collapse -

C PROGRAM CORRECTION

by john_bosko In reply to C PROGRAM CORRECTION

Poster rated this answer

Back to Web Development Forum
11 total posts (Page 1 of 2)   01 | 02   Next

Related Discussions

Related Forums