cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp/1999/01/18/14:00:32

Subject: Re: Need help with c!
Approved: clc AT plethora DOT net
References: <clcm-19990117-0010 AT plethora DOT net>
From: Francis Glassborow <francis AT robinton DOT demon DOT co DOT uk>
X-Newsreader: Turnpike (32) Version 3.05 <TilyaeicE$WmMOP9F8P4$y3lmP>
Organization: Southfield Microcomputer SS
Lines: 47
Mime-Version: 1.0
Newsgroups: comp.os.msdos.djgpp,comp.lang.c.moderated
Message-ID: <clcm-19990118-0001@plethora.net>
Originator: clcm AT plethora DOT net (Comp Lang C'Moderated)
Date: Mon, 18 Jan 1999 19:00:01 GMT
NNTP-Posting-Host: 205.166.146.5
X-Trace: ptah.visi.com 916686001 205.166.146.5 (Mon, 18 Jan 1999 13:00:01 CDT)
NNTP-Posting-Date: Mon, 18 Jan 1999 13:00:01 CDT
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

My compliments on actually trying to walk your code.  Howevee there are
a number of warts (such as writing void main() ) that I guess others
will point out to you.  However you have walked into a well known trap
which I highlight below:


In article <clcm-19990117-0010 AT plethora DOT net>, Mohanaraj Gopala Krishnan
<saradiya AT bigfoot DOT com> writes
>void open_file(int * pages_done, int array_size)

Would be a good idea to have this function return a suaccess/failure
indicator

>{
>        int i=0;
>
>        if((fptr=fopen("chapter.dat", "r")) !=NULL) {
>
>fseek(fptr,0L,SEEK_SET);
>
>for(i=0;i<array_size;i++) {

OK you count through from 0 to array_size
>
>fscanf(fptr,"%d",*(pages_done++));
but here we have a very nasty trap
pages_done was a pointer to an int (I guess it is to be an array)
that means *(pages_done++) evaluates to the CONTENTS of the current
address in pages_done before incrementing the address.  But if you check
fscanf you will find that it needs an address of an int.

you need to write:
fscanf(fptr,"%d", pages_done+i);

You could use the increment operator but I find the base+offset better
in this type of situation, though that is a matter of personal style.




>
>}

Francis Glassborow      Chair of Association of C & C++ Users
64 Southfield Rd
Oxford OX4 1PA          +44(0)1865 246490
All opinions are mine and do not represent those of any organisation
-- 
comp.lang.c.moderated - clcm AT plethora DOT net

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019