Path: utzoo!utgpu!attcan!uunet!lll-winken!lll-tis!helios.ee.lbl.gov!ux1.lbl.gov!beard From: beard@ux1.lbl.gov (Patrick C Beard) Newsgroups: comp.sys.mac.programmer Subject: Re: LSC 3.0 scanf deletes Summary: Don't use scanf!!! Keywords: delete, scanf Message-ID: <587@helios.ee.lbl.gov> Date: 2 Aug 88 22:23:22 GMT References: <2559@pt.cs.cmu.edu> Sender: usenet@helios.ee.lbl.gov Reply-To: beard@ux1.lbl.gov (Patrick C Beard) Organization: Lawrence Berkeley Laboratory, Berkeley Lines: 44 In article <2559@pt.cs.cmu.edu> phd@speech1.cs.cmu.edu (Paul Dietz) writes: >I'm tired of fighting this one. Does anybody know how to delete >characters when you make a mistake typing during an LSC scanf? >Any suggestions would be appreciated. Thanks! > >Paul H. Dietz ____ ____ The answer to your question is, DON'T USE SCANF! I have always hated the way scanf treats the user who assumes he can edit his command line. A better approach to getting lines of input and parsing them from the user is to use gets() and then sscanf(). For example: Instead of: float foo() { float in_value; printf("enter a floating point value: "); scanf("%f",&in_value); /* yuck, user can't edit his input! */ return(in_value); } use: float foo() { 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); } I hope this helps. +=============================================================+ | Patrick C. Beard | | Lawrence Berkeley Laboratory | | Automated Supernova Search | +-------------------------------------------------------------+ | PCBeard@LBL.gov (arpa only) | +=============================================================+