Message-ID: <37B504AA.7E9A@iquest.net> From: Jeremy Brown <"peart2112"@iquest.net> Organization: Purdue University X-Mailer: Mozilla 3.0Gold (Win95; I) MIME-Version: 1.0 Newsgroups: comp.os.msdos.djgpp Subject: Re: Help to read array from text file References: <7p2s92$6b95e$2 AT titan DOT xtra DOT co DOT nz> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 56 Date: Sat, 14 Aug 1999 00:54:50 -0500 NNTP-Posting-Host: 209.43.69.120 X-Trace: news1.iquest.net 934610145 209.43.69.120 (Sat, 14 Aug 1999 00:55:45 EDT) NNTP-Posting-Date: Sat, 14 Aug 1999 00:55:45 EDT To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Steve wrote: > > Well, > > I am trying to read a text file which contains 5 rows and 5 columns of > numbers into an array, then print out the array on screem in the same format > that is was in the text file so that individual parts of the array can be > summed, counted etc. so far, I have not been able to do so, any help with > this would be very welcome. > > Included is what I have come up with so far, yer ok, so I am also new to > this, there could be obvious mistakes in there of which I cannot see. Below > is the file that I have been working on. > > Steve > > #include > #include > > main() > { > FILE * aa; > char fname[81], t[5][5]; > > int a, ch, team, last; > > printf("Enter name of file to read: "); > scanf("%80s", fname); > > aa = fopen(fname, "r"); > if (aa == NULL) { > > fprintf(stderr, "File cannot be opened.\n"); > exit(1); > } > > while ((ch = getc(aa)) >= 0) { /* while not EOF */ > for (a = 0; a <= 26; ++a) > fscanf(stderr, "%s", t[a]); > > fprintf(stderr, "%s \n", t[a]); > } > > fclose(aa); > return 0; > } try readln(). jeremy -- "I can't pretend a stranger is a long awaited friend."-Neil Peart peart AT purdue DOT edu http://expert.cc.purdue.edu/~brown6