From: av568 AT rgfn DOT epcc DOT edu (Beautiful Savior Lutheran Church) Newsgroups: comp.os.msdos.djgpp Subject: Re: possible bug? Date: 29 Mar 1997 06:19:58 GMT Organization: The Rio Grande Free-Net, El Paso Community College, El Paso, TX Lines: 58 Message-ID: <5hicae$7m1@news.epcc.edu> References: <333C801C DOT 112D AT pluto DOT njcc DOT com> NNTP-Posting-Host: rgfn.epcc.edu To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp shearer AT pluto DOT njcc DOT com wrote: > This is a multi-part message in MIME format. > --------------4E3873DB632C > Content-Type: text/plain; charset=us-ascii > Content-Transfer-Encoding: 7bit > ++i > i++ > when each of these is used in a loop such as below, > shouldn't the decision to pre-fix or to post-fix > affect the output of said loop? > the following, compiled and run under djgpp(gcc272), > with the condition of the for loop being ++i or i++, > seems to result in the same for both cases. > such shouldn't be the case, should it? I don't see the problem. ++i is used in the code as the third part of a for loop. This third part is executed at the completion of each loop iteration. It makes no difference whether the pre- or post-fix operator is used. (I think the poster thought a prefix ++ would cause the variable to increment *before* the loop. This is not the case.) > --------------4E3873DB632C > Content-Type: text/plain; charset=us-ascii > Content-Transfer-Encoding: 7bit > Content-Disposition: inline; filename="test.c" > #define SNUL '\0' > #include > main(){ > char a[10]; > int i; > FILE *IN=NULL; > if((IN=fopen("test.txt","r"))==NULL) > { > printf("\nfile does not exist"); > exit(2); > } > for (i=0;i<9;++i) > { a[i]= (char) fgetc(IN); > printf("%i\t%c\n",i,a[i]); > }; > a[i] = SNUL; > printf("%i\t%c\n",i,a[i]); > } > --------------4E3873DB632C-- -- Beautiful Savior Evangelical Lutheran Church - av568 AT rgfn DOT epcc DOT edu We have what you need-- A Savior!