This is a discussion on writing program from a book within the comp.unix.solaris forums, part of the Solaris Operating System category; --> >I wrote that program from a book that my compile that program >correctly under C++ compiler but I got ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| >I wrote that program from a book that my compile that program >correctly under C++ compiler but I got those errors for compiling >under unix !! >main (argc,argv) >{ >int argc; >char *argv[50]; since you're using the old K&R-style parameter declarations, remove that "{" after main. -- mac the naïf |
| |||
| This isn't right. This isn't even wrong! hpy_awad@yahoo.com wrote: > I wrote that program from a book that my compile that program > correctly under C++ compiler but I got those errors for compiling > under unix !! > > Errors- > -------- > part10_iti_r01_ch10_verbo_menu_driven_programs.c: In function `main': > part10_iti_r01_ch10_verbo_menu_driven_programs.c:6 : warning: > declaration of `argc' shadows a parameter > part10_iti_r01_ch10_verbo_menu_driven_programs.c:7 : warning: > declaration of `argv' shadows a parameter > part10_iti_r01_ch10_verbo_menu_driven_programs.c:2 2: syntax error > before '{' token > > Program- > -------- > #include <stdio.h> > //part10_iti_r01_ch10_verbo_menu_driven_programs.c > > main (argc,argv) > { > int argc; > char *argv[50]; > { > int option; > do > { > //Display menu > display_menu(); > > //Initite appropriate program or exit > if (option!=7) //exit > call_program(option,argv); > } > while (option!=7); > } > display_menu() > { > system("clear"); > printf ("\n TV Rental system"); > printf ("\n ----------------"); > printf("\n\n 1 Set up new customer"); > printf("\n\n 2 Change existing customer record"); > printf("\n\n 3 Add new customer record"); > printf("\n\n 4 Delete customer record"); > printf("\n\n 5 Print customer bills"); > printf("\n\n 6 display a customer record"); > printf("\n\n 7 Exit"); > } > > > user_selection() > { > int opt; > printf("\n\n Enter required option number (1-7) "); > scanf("%d",&opt); > return(opt); > } > > call_program(opt,argv) > int opt; > char *argv[]; > { > switch(opt) > { > case 1: spawnvp(0,"a.obj",argv); > delay(); > break; > > default > delay(); > } > } > > > delay() > { > int i; > for (i=0;i<=20000;++i); > } -- "It is impossible to make anything foolproof because fools are so ingenious" - A. Bloch |
| |||
| Dragan Cvetkovic wrote: > Actually, even that one won't work with C++ (remember, OP is using a C++ > compiler). I haven't a clue why he posted it to comp.lang.c, where we don't give a flip about C++. I answered the post where I read it, in comp.lang.c. There are many correct answers in comp.lang.c that don't work with C++. And we don't care. -- Martin Ambuhl |
| |||
| On Thu, 29 Jan 2004, Martin Ambuhl wrote: > There are many correct answers in comp.lang.c that don't work with C++. > And we don't care. Ah, I was wondering when the typical warm and cuddly c.l.c. comment would show up... ;-) -- Rich Teer, SCNA, SCSA President, Rite Online Inc. Voice: +1 (250) 979-1638 URL: http://www.rite-online.net |
| |||
| On 28 Jan 2004 10:33:24 -0800, ehab_aziz2001@yahoo.com (hpy_awad@yahoo.com) wrote in comp.lang.c: > I wrote that program from a book that my compile that program > correctly under C++ compiler but I got those errors for compiling > under unix !! > > Errors- > -------- > part10_iti_r01_ch10_verbo_menu_driven_programs.c: In function `main': > part10_iti_r01_ch10_verbo_menu_driven_programs.c:6 : warning: > declaration of `argc' shadows a parameter > part10_iti_r01_ch10_verbo_menu_driven_programs.c:7 : warning: > declaration of `argv' shadows a parameter > part10_iti_r01_ch10_verbo_menu_driven_programs.c:2 2: syntax error > before '{' token > > Program- > -------- > #include <stdio.h> > //part10_iti_r01_ch10_verbo_menu_driven_programs.c > > main (argc,argv) > { > int argc; > char *argv[50]; > { 1. Learn some manners and don't cross-post to so many unrelated groups. 2. Burn that book, immediately. -- Jack Klein Home: http://JK-Technology.Com FAQs for comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html comp.lang.c++ http://www.parashift.com/c++-faq-lite/ alt.comp.lang.learn.c-c++ http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html |
| |||
| "Jack Klein" <jackklein@spamcop.net> wrote in message news:attg1015gel8762ie361jpohfk58ggqrr1@4ax.com... > On 28 Jan 2004 10:33:24 -0800, ehab_aziz2001@yahoo.com > (hpy_awad@yahoo.com) wrote in comp.lang.c: > > > I wrote that program from a book that my compile that program > > correctly under C++ compiler but I got those errors for compiling > > under unix !! > > > > Errors- > > -------- > > part10_iti_r01_ch10_verbo_menu_driven_programs.c: In function `main': > > part10_iti_r01_ch10_verbo_menu_driven_programs.c:6 : warning: > > declaration of `argc' shadows a parameter > > part10_iti_r01_ch10_verbo_menu_driven_programs.c:7 : warning: > > declaration of `argv' shadows a parameter > > part10_iti_r01_ch10_verbo_menu_driven_programs.c:2 2: syntax error > > before '{' token > > > > Program- > > -------- > > #include <stdio.h> > > //part10_iti_r01_ch10_verbo_menu_driven_programs.c > > > > main (argc,argv) > > { > > int argc; > > char *argv[50]; > > { > Lets see, the error messages say that there is a problem in function main. Good place to start. It then goes on to line 6, your "int argc;" line. mmmm what is wrong here? Your function declaration is wrong. You are also attempting to use an old style of C function delcarations. Try.... #include <stdio.h> main(int argc; char **argv) { // Now you can continue with the code > 1. Learn some manners and don't cross-post to so many unrelated > groups. Agreed. > > 2. Burn that book, immediately. > Might not be such a bad idea if the code was correctly taken out of the book. Brad |
| |||
| Rich Teer wrote: > I'm reading in this in comp.unix.solaris: I humbly submit that > my forthcoming book, Solaris Systems Prorgamming, should be on > your shopping list (in addition to a good C tutorial - my book > assumes some C knowledge). Relief! I was getting withdrawal symptoms from lack of recent plugs for the book ;-) Thanks Rich! ( And I decided to only bother CUS with this - we *are* the only ones with a sense of humour :-) ) |
| |||
| Brad wrote: > > "Jack Klein" <jackklein@spamcop.net> wrote in message > news:attg1015gel8762ie361jpohfk58ggqrr1@4ax.com... > > On 28 Jan 2004 10:33:24 -0800, ehab_aziz2001@yahoo.com > > (hpy_awad@yahoo.com) wrote in comp.lang.c: > > > > > I wrote that program from a book that my compile that program > > > correctly under C++ compiler but I got those errors for compiling > > > under unix !! > > > > > > Errors- > > > -------- > > > part10_iti_r01_ch10_verbo_menu_driven_programs.c: In function `main': > > > part10_iti_r01_ch10_verbo_menu_driven_programs.c:6 : warning: > > > declaration of `argc' shadows a parameter > > > part10_iti_r01_ch10_verbo_menu_driven_programs.c:7 : warning: > > > declaration of `argv' shadows a parameter > > > part10_iti_r01_ch10_verbo_menu_driven_programs.c:2 2: syntax error > > > before '{' token > > > > > > Program- > > > -------- > > > #include <stdio.h> > > > //part10_iti_r01_ch10_verbo_menu_driven_programs.c > > > > > > main (argc,argv) > > > { > > > int argc; > > > char *argv[50]; > > > { > > > Lets see, the error messages say that there is a problem in function main. > Good place to start. > It then goes on to line 6, your "int argc;" line. mmmm what is wrong here? > > Your function declaration is wrong. You are also attempting to use an old > style of C function delcarations. Try.... > > #include <stdio.h> > > main(int argc; char **argv) > { You misspelled int main(int argc, char **argv) -- pete |
| |||
| "pete" <pfiland@mindspring.com> wrote in message news:4018F6C0.1C14@mindspring.com... > Brad wrote: > > > > "Jack Klein" <jackklein@spamcop.net> wrote in message > > news:attg1015gel8762ie361jpohfk58ggqrr1@4ax.com... > > > On 28 Jan 2004 10:33:24 -0800, ehab_aziz2001@yahoo.com > > > (hpy_awad@yahoo.com) wrote in comp.lang.c: > > > > > > > I wrote that program from a book that my compile that program > > > > correctly under C++ compiler but I got those errors for compiling > > > > under unix !! > > > > > > > > Errors- > > > > -------- > > > > part10_iti_r01_ch10_verbo_menu_driven_programs.c: In function `main': > > > > part10_iti_r01_ch10_verbo_menu_driven_programs.c:6 : warning: > > > > declaration of `argc' shadows a parameter > > > > part10_iti_r01_ch10_verbo_menu_driven_programs.c:7 : warning: > > > > declaration of `argv' shadows a parameter > > > > part10_iti_r01_ch10_verbo_menu_driven_programs.c:2 2: syntax error > > > > before '{' token > > > > > > > > Program- > > > > -------- > > > > #include <stdio.h> > > > > //part10_iti_r01_ch10_verbo_menu_driven_programs.c > > > > > > > > main (argc,argv) > > > > { > > > > int argc; > > > > char *argv[50]; > > > > { > > > > > Lets see, the error messages say that there is a problem in function main. > > Good place to start. > > It then goes on to line 6, your "int argc;" line. mmmm what is wrong here? > > > > Your function declaration is wrong. You are also attempting to use an old > > style of C function delcarations. Try.... > > > > #include <stdio.h> > > > > main(int argc; char **argv) > > { > > You misspelled > > int main(int argc, char **argv) > Correct, thanx. Brad |
| ||||
| On Wed, 28 Jan 2004 20:36:18 GMT, Default User <first.last@boeing.com.invalid> wrote: > Lew Pitcher wrote: > (re: main (argc, argv) /*spurious*/{ int argc; char *argv[50]; { etc.) > > You are compiling bad K&R (pre-ANSI) C with ANSI C99 / C++ comments using a > > C++ compiler, and expecting it to compile properly and execute. > > It's not even old-style C, because he has an opening brace before the > argc and argv declarations, which then turns them into local variables > (hence the error message). > It is facially valid oldstyle C89 (or prestandard), because the parameters argc and argv are implicitly int, as is the return from main(); the parameters are then shadowed by locals which is perfectly legal though rarely wise and (hence) was only a warning not an error. The result is Undefined Behavior because main() is only defined to work for zero arguments (void) or two arguments (int, char**), although in practice on many (most?) implementations since the parameters argc and argv are not (cannot be) accessed this would still (sort of) work -- in the absence of the OP's *other* bugs. - David.Thompson1 at worldnet.att.net |