Mail Archives: djgpp/1997/03/29/08:45:35
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 <stdio.h>
> 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!
- Raw text -