Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm Sender: cygwin-owner AT sourceware DOT cygnus DOT com Delivered-To: mailing list cygwin AT sourceware DOT cygnus DOT com From: cwebb AT emailbox DOT hdtv DOT lucent DOT com Date: Mon, 10 May 1999 12:53:58 -0400 Message-Id: <199905101653.MAA00892@soul.hdtv.lucent.com> To: cygwin AT sourceware DOT cygnus DOT com Subject: What is the correct behavior for the following code? Content-Type: text Hi everyone, I have been having some portability problems with scanf %i and %X. Attached is a program that illustrates the problem. Can someone tell me what is the "correct" behavior for this code, and how I can avoid these issues (if possible). Thanks, Chip Webb #include int okcnt=0; int errcnt=0; check(int c, int i, int ec, int ei, int tno) { if((i==ei) && (c==ec)){ okcnt++; printf("OK (%d)\n",tno); } else{ errcnt++; if(c!=ec) printf("ERROR(%d): c=%d, expect=%d\n",tno,c,ec); if(i!=ei) printf("ERROR(%d): i=0x%X, expect=0x%X\n",tno,i,ei); } } main() { FILE *fp; int i,c,tno=1; system("echo 0x12345678 > foo"); system("echo 0xDEADBEEF >> foo"); fp = fopen("foo","r"); i=0; c=fscanf(fp,"%i",&i); check(c,i,1,0x12345678,tno++); i=0; c=fscanf(fp,"%i",&i); check(c,i,1,0xDEADBEEF,tno++); fclose(fp); fp = fopen("foo","r"); i=0; c=fscanf(fp,"0x%X",&i); check(c,i,1,0x12345678,tno++); i=0; c=fscanf(fp,"0x%X",&i); check(c,i,1,0xDEADBEEF,tno++); fclose(fp); printf("Total OK = %3d\n", okcnt); printf("Total errors = %3d\n", errcnt); } -- Want to unsubscribe from this list? Send a message to cygwin-unsubscribe AT sourceware DOT cygnus DOT com