delorie.com/archives/browse.cgi | search |
X-Authentication-Warning: | delorie.com: mail set sender to djgpp-bounces using -f |
NNTP-Posting-Date: | Sat, 02 Dec 2006 20:38:11 -0600 |
Message-ID: | <45723541.408553CB@yahoo.com> |
Date: | Sat, 02 Dec 2006 21:24:01 -0500 |
From: | CBFalconer <cbfalconer AT yahoo DOT com> |
Organization: | Ched Research http://cbfalconer.home.att.net |
X-Mailer: | Mozilla 4.75 [en] (Win98; U) |
X-Accept-Language: | en |
MIME-Version: | 1.0 |
Newsgroups: | comp.os.msdos.djgpp |
Subject: | Multi level ungetc |
Lines: | 63 |
NNTP-Posting-Host: | 216.195.145.77 |
X-Trace: | sv3-2ryNwoJ93wfAcxZXTaTHDYlD23PeO3xOd6DTh33WU5VikhVRedTyf7vBOjng/yCdrre/tcIeBKVq1/r!SDbLEkqrQsc54JAAae9nE9eQk9oxuXwZfkMGdkwo4Se51hFn6tss/NLWJZCc1A== |
X-Complaints-To: | abuse AT gwi DOT net |
X-DMCA-Complaints-To: | abuse AT gwi DOT net |
X-Abuse-and-DMCA-Info: | Please be sure to forward a copy of ALL headers |
X-Abuse-and-DMCA-Info: | Otherwise we will be unable to process your complaint properly |
X-Postfilter: | 1.3.32 |
To: | djgpp AT delorie DOT com |
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp |
Reply-To: | djgpp AT delorie DOT com |
A few days ago it struck me that most systems would have no problem implementing multi-level ungetc, provided it didn't try to cross line ending boundaries. Without that complication it will usually simply have to adjust an internal pointer to the input buffer. So I wrote a little program to test it, and lo and behold, DJGPP does just that. Congratulations DJ. That means strtod() can have the proper semantics in the presence of input such as "123.4e-x", and I have finally seen a reason for making strtod() a system routine. #include <stdio.h> #include <stdlib.h> #define MAXLN 10 int main(void) { char line[MAXLN + 1]; int ix, ch; puts("Test ability to ungetc for multiple chars in one line"); fputs("Enter no more than 10 chars:", stdout); fflush(stdout); ix = 0; while ((EOF != (ch = getchar())) && ('\n' != ch)) { if (MAXLN <= ix) break; line[ix++] = ch; } line[ix] = '\0'; if ('\n' != ungetc('\n', stdin)) { puts("Can't unget a '\\n'"); return(EXIT_FAILURE); } puts(line); puts("Trying to push back the whole line"); while (ix > 0) { ch = ungetc(line[--ix], stdin); if (ch == line[ix]) putchar(ch); else { putchar(line[ix]); puts(" failed to push back"); return(EXIT_FAILURE); } } puts("\nTrying to reread the whole line"); while ((EOF != (ch = getchar())) && ('\n' != ch)) { if (ix++ == MAXLN) break; putchar(ch); } return 0; } /* main tungetc.c */ [1] c:\c\junk>tungetc Test ability to ungetc for multiple chars in one line Enter no more than 10 chars:12345 12345 Trying to push back the whole line 54321 Trying to reread the whole line 12345 -- Chuck F (cbfalconer at maineline dot net) Available for consulting/temporary embedded and systems. <http://cbfalconer.home.att.net>
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |