Path: utzoo!attcan!uunet!husc6!cmcl2!rutgers!ucsd!ucbvax!dewey.soe.berkeley.edu!oster From: oster@dewey.soe.berkeley.edu (David Phillip Oster) Newsgroups: comp.sys.mac.programmer Subject: Re: LSC 3.0 scanf deletes Keywords: delete, scanf Message-ID: <25510@ucbvax.BERKELEY.EDU> Date: 7 Aug 88 02:10:43 GMT References: <2559@pt.cs.cmu.edu> <587@helios.ee.lbl.gov> Sender: usenet@ucbvax.BERKELEY.EDU Reply-To: oster@dewey.soe.berkeley.edu.UUCP (David Phillip Oster) Organization: School of Education, UC-Berkeley Lines: 74 In article <587@helios.ee.lbl.gov> beard@ux1.lbl.gov (Patrick C Beard) writes: >{ > float in_value; > char buf[80]; /* overconservative */ > > printf("enter ... "); > gets(buf); /* user can use backspace to edit */ > sscanf(buf,"%f",&in_value); > return(in_value); >} Are you from the moon? Why would anyone want to do such a silly thing? The correct solution is: #if MAC #include #define TEXTITEM 3 /* GetDIHandle - return handle from current dialog item */ Handle GetDIHandle(item)short item;{ short type; Handle hand; Rect r; GetDItem(thePort, item, &type, &hand, &r); return hand; } /* foo- get a floating point number from the user */ float foo(){ float f; Str255 s; SetPort(GetNewDialog(FLOAT1, NIL, -1L)); for(;;){ ModalDialog(NIL, &item); switch(item){ case OK: GetIText(GetDIHandle(TEXTITEM), s); PtoCstr( (char *) s); if(1 != sscanf(s,"%f", &f) || OutOfBounds(f)){ /* bad number, beep and reselect */ SysBeep(1); SelIText(thePort, TEXTITEM, 0, 9999); break; } DisposDialog(thePort); return f; /* user wants out */ case Cancel: DisposDialog(thePort); return BADFLOAT; /* user wants out */ } } } /* Where FLOAT1 is the resource id of a dialog with an okay button as item 1, a cancel button as item 2, an edit text box as item 3, and a prompt statictext string as item 4. Just create it in ResEdit. */ #else ... whatever ludicrous nonsense you have to do on other machines #endif Get with it guys, this is Macintosh, not some 1960's vintage teletype. --- David Phillip Oster --When you asked me to live in sin with you Arpa: oster@dewey.soe.berkeley.edu --I didn't know you meant sloth. Uucp: {uwvax,decvax,ihnp4}!ucbvax!oster%dewey.soe.berkeley.edu