Mail Archives: djgpp/1998/11/02/22:50:21
From: | "Joe Ury" <j DOT ury AT unsw DOT edu DOT au>
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | why is output different each time?
|
Date: | 3 Nov 1998 03:33:30 GMT
|
Organization: | University of New South Wales
|
Lines: | 89
|
Message-ID: | <01be06da$d35edfc0$5640ab95@JUry.law.unsw.edu.au>
|
NNTP-Posting-Host: | law86.law.unsw.edu.au
|
X-Newsreader: | Microsoft Internet News 4.70.1155
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Reply-To: | djgpp AT delorie DOT com
|
Why do I get differing output each time. Its reading a marked up text file
and
the first time it works ok then the next time what looks like memory dump
is added
at the beginning of each line then the next time more of the same and after
a while
its ok again - should I be flushing memory somewhere? Is there a bug in
memchar - I've looked but it seems that the bug that was their is
fixed...any ideas? help and thanks.
sample of input file:
|A.I.J.A. briefing*Australian Institute of Jewish Affairs. Melbourne.
*NMCHS *May 1991+ *NMOR *1994+ *NU:J *no. 1 (Feb. 1991)+ * * * * * * * * *
* * * * *
|A.I.J.A. papers.* *NMCHS *Aug. 1992+ *NMOR *1996+ * * * * * * * * * * * *
* * * *
|A.I.J.A. survey*Australian Institute of Jewish Affairs. Melbourne. *NMOR
*1996+ *NU:J *no. 1 (Apr.-May 1986)+ *VMAK *1986- * * * * * * * * * * * * *
*
|A.J.A. quarterly*Anglo-Jewish Association. London. *NGS *v. 1 (1955) -8
(1966) * * * * * * * * * * * * * * * * * *
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <conio.h>
#include <string.h>
char Pause()
{
char c;
printf("\nPress Enter to continue...");
while ((c = getchar()) != '\n') { }
return c;
}
int main()
{
char array [1000];
char *t, *x;
FILE *f1, *f2;
char delimit[] = "*";
int i = 1;
// char c;
int len;
clrscr();
fflush(f1);
if((f1= fopen("jewish.prn" , "r" )) == NULL ) {
perror( "Cannot open file for reading" ) ;
exit( EXIT_FAILURE ) ;
}
if((f2= fopen("text1.out" , "w" )) == NULL ) {
perror( "Cannot open file for writing" ) ;
exit( EXIT_FAILURE ) ;
}
while(fgets( array , sizeof( array ) , f1 ) != NULL ){
// c = fgetc(f1);
// fputc(c, stdout);
t = strtok(array, delimit);
while (t) {
len = strlen(t);
do {
x = (char *)memchr(t, '|', len);
if (x)
*x = '\n';
} while (x);
fputs(x,f2);
if (len > 1)
fprintf(f2, "%s\n", t);
t = strtok(NULL, delimit);
}
}
exit(1);
return 0 ;
}
**********************************************************
Joe
j DOT ury AT unsw DOT edu DOT au
- Raw text -