Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!umich!umeecs!msi.umn.edu!cs.umn.edu!kksys!edgar!mmug!p510.f22.n282.z1.fidonet.org!Jim.Spencer From: Jim.Spencer@p510.f22.n282.z1.fidonet.org (Jim Spencer) Newsgroups: comp.sys.mac.programmer Subject: MPW C 3.1 scanf problem Message-ID: <4.279FC79F@mmug.mn.org> Date: 24 Jan 91 05:16:26 GMT Sender: ufgate@mmug.mn.org (newsout1.26) Organization: FidoNet node 1:282/22.510 - Macintosh SmorgasBo, Bloomington MN Lines: 11 In a message <38337@cup.portal.com> 22 Jan 91 David_Anthony_Guevara@cup.portal.com writes D> If I put a newline in after the prompt, the scanf works. If I D> leave the code as stated above, I'll get some garbage. I'm building D> this under MPW as a tool. Is this a known problem/undocumented D> feature of MPW C? What you are seeing is MPW's normal way of passing input: just as when you send a command, if you have a selection, the selection will be passed. If you have no selection but simply have your cursor some place in the line, then the whole line is getting sent. When you do textbook type code with things like scanf(), you will have the cursor at the end of your prompt, you then type the integer in your case and press enter. What gets sent is the entire line, INCLUDING THE PROMPT. You aren't really getting garbage: you are seeing the result of scanf() trying to interpret "Input" as an integer. Your options are to either put a carriage return in or to select the integer before pressing the enter key.