How to enter a C EOF character in terminal

I already searched and went to this thread here which has been archieved... http://discussions.apple.com/thread.jspa?messageID=5069197&#5069197
It says EOF can be entered using ctrl-d but that doesn't seem to end the input stream. my code is as follows...
#include<stdio.h>
main()
int c;
while((c=getchar())!=EOF)
putchar(c);
any help is appreciated.
PS: Referring to The C programming language, K&R
Message was edited by: AceNeerav
Message was edited by: AceNeerav

First, and code you post should be wrapped in
... your code here ...
tags. That will make sure the forum does not see coding syntax as forum formatting meta characters, and it will preserve your indentation.
As the thread you posted suggests, there is no EOF character.
However, at the lowest level the read() system call (somewhere under getchar()), can be told there is no more input, and it will return 0, which somewhere along the way, the getchar() code converts to EOF (where EOF is actually -1).
Depending on what the read() system call is reading, there are different even lower level rules for indicating end-of-file. In your example, you are reading from the Terminal, and the tty driver (NOT the Terminal, but the tty driver) has the convention that if it is in the correct mode, it will tell the read() system call end-of-file when the tty driver sees a specific character.
The normal Unix convention is that Control-D is used to indicate end-of-file. However, this can be changed (but normally it is not), or the tty driver can be put into "RAW" mode which will pass every character entered directly to the reading program and do nothing.
You can see the current terminal driver settings using the
stty all
command. Here are the settings for my Terminal session:
stty all
speed 9600 baud; 13 rows; 145 columns;
lflags: icanon isig iexten echo echoe -echok echoke -echonl echoctl
-echoprt -altwerase -noflsh -tostop -flusho pendin -nokerninfo
-extproc
iflags: -istrip icrnl -inlcr -igncr ixon -ixoff ixany imaxbel iutf8
-ignbrk brkint -inpck -ignpar -parmrk
oflags: opost onlcr -oxtabs -onocr -onlret
cflags: cread cs8 -parenb -parodd hupcl -clocal -cstopb -crtscts -dsrflow
-dtrflow -mdmbuf
discard dsusp eof eol eol2 erase intr kill lnext
^O ^Y ^D <undef> <undef> ^? ^C ^U ^V
min quit reprint start status stop susp time werase
1 ^ ^R ^Q ^T ^S ^Z 0 ^W
Notice on the 4th from the bottom row, it says 'eof' and below that it says ^D (Control-D). This basically says that the tty driver will tell the read() system call end-of-file when the tty driver sees Control-D.
Control-Z is used for job control, which suspends your current process and allows you to start a different job, optionally putting the current job in the background (Control-Z, jobs, bg and fg commands). Control-Z has nothing to do with end-of-file on a Unix based tty interface.
However, I know that back in the good old days of DOS, a real Control-Z character in a text file WAS the end-of-file indicator. This was bad design even back then. Thankfully, Unix predated DOS and never used that ugly convention.
As to your program, it works for me:
#include<stdio.h>
main()
int c;
while((c=getchar())!=EOF)
putchar(c);
I compiled and ran it:
command prompt> gcc example.c -o example
command prompt> example
the quick brown fox jumps over the lazy dog # I typed this
the quick brown fox jumps over the lazy dog # putchar() text
^D # I entered Control-D
command prompt> # the program ends, and I get the command prompt
If you are not seeing this behavior, then I would look closely at your stty settings.

Similar Messages

  • HOW can I enter text using Japanese character sets?

    The "Text, Plates, Insets" section of the LOOKOUT(6.01) Help files states:
    "Click the » button to the right of the Text field to expand the field for multiple line entries. You can enter text using international character sets such as Chinese, Korean, and Japanese."
    Can someone please explain HOW to do this? Note, I have NO problem inputting Hirigana, Katakana, and Kanji into MS WORD; the keyboard emulates the Japanese layout and characters (Romaji is default) and the IME works fine converting Romaji, and I can also select charcters directly from the IME Pad. I have tried several different fonts with success and am currently using MS UI Gothic.ttf as default. Again, everything is normal and working in a predictable manner within Word.
    I cannot get these texts into Lookout. I can't cut/paste from HTML pages or from text editors, even though both display properly. Within Lookout with JP selected as language/keyboard, when trying to type directly into the text field, the IME CORRECTLY displays Hirigana until <enter> is pressed, at which point all text reverts to question marks (?? ???? ? ?????). If I use the IME Pad, it does pretty much the same. I managed to get the "Yen" symbol to display, though, if that's relevant. As I said, font selected (in text/plate font options) is MS UI Gothic with Japanese as the selected script. Oddly enough, at this point the "sample" window is showing me the exact Hirigana character I want displayed in Lookout, but it won't. I've also tried staying in English and copying unicode characters from the Windows Character Map. Same results (Yen sign works, Hirigana WON'T).
    Help me!
    JW_Tech

    JW_Tech,
    Have you changed the regional setting to Japanese?
    Doug M
    Applications Engineer
    National Instruments
    For those unfamiliar with NBC's The Office, my icon is NOT a picture of me
    Attachments:
    language.JPG ‏50 KB

  • How do I enter my existing 26 character wep network key on my airport express. I have tried using a preceding $ to no avail

    How do I enter my existing 26 character wep network key on my airport express. I have tried using a preceding $ to no avail

    The WEP standard provides support for either:
    A 10 hexidecimal digit or 5 ASCII character key for 40-bit WEP,  OR
    A 26 hexidecimal digit or 13 ASCII character key for 128-bit WEP
    In order to make things easier, vendors use certain algorithms to convert simple alphanumeric passwords (or passphrases) into HEX keys, thus enabling the use of simple easy to remember WEP password rather than lengthy HEX keys. The problem is that different vendors use different algorithms to generate the HEX key and therefore a ASCII password on an AirPort Express will be hashed differently than on a non-Apple client and vice versa.
    In addition, the 802.11n AirPorts do NOT support either 40-bit or 128-bit WEP in the "n" Radio Mode. You will have to switch to one of the non-"n" modes to access these wireless security options.
    When operating in 802.11n, the only WEP option is the WEP (Transitional Network Security) mode. Note: This mode only supports using 13 ASCII character keys. This would be the reason that you are not able to enter a 26 hexidecimal digit key. 
    You may find the following Apple Support article helpful: AirPort: Joining an encrypted WEP  or WPA Wi-Fi Network

  • How to enter the special character ALT225 - the double S in Germany

    Hi,
    I use the double S of the German keyboard in my wifi password.
    Any idea how to enter it ?
    This is this one : ß
    Thanks,
    Patrick

    touch and hold the "S"...you will get different options for the letter...it must be a lowercase "s" and not and uppercase "S" otherwise you won't get what you are looking for. So, make sure the arrow isn't highlighted

  • How to enter Backslash "\" on E71?

    That could be a weird question, but anybody know how to enter the Back Slash on E71 "\"... I need it to enter my corporate mail, but where I can found that? It´s not on QWERTY keyboard, neither on "Car" Key, where is it? Thanks for the help.
    Message Edited by nj7_ on 26-Feb-2009 11:54 PM

    try gong to your messaging > options > settings >  text message > character encoding > make sure its full support.
    Mark me a KUDOS if this has helped...

  • How to enter French or German chars?

    Hi,
    How the enter French or German chars?
    I have installed French language packages.
    Kind regards,
    Daniel

    Hello.
    First of all: Not all programs support the two methods I describe below.
    Method 1:
    If you have a french keyboard you may simply use this. Unfortunately some programs do not support the Alt-GR key.
    Method 2:
    Using the "Compose" key (If you have a non-Sun keyboard: Ctrl+Alt+F1). Example: Press "Compose" (and release it), then type two characters (example: "A" (= Shift-a) and " " " (= Shift-2)). You'll get a combined character (in the example: "�"). There is a list of combinations and results from Sun. Not all programs support this method.
    Martin

  • HT3986 How to enter euro sign on apple keyboard

    How to enter Euro sign on apple keyboard

    System Preferences/ Keyboard, make sure Keyboard is selcted and near the bottom is button to click, Show Keyboard & Character Viewer in menu bar...... it's in there somewhere's..... (search bar at the bottom)

  • How to enter opening balance for GL A/C(Ex. Bank A/C, Cash A/C, Vendor A/C)

    Hi Expert,
    How to enter opening balance for last year to closing balance to this year opening balance explain deeply helpful for me Thanks in advance.
    Example
    All Bank A/C, Cash Book, Vendors, Customers, like that how to enter closing to opening balance.
    With Warm regards,
    Selva

    Dear,
    As per SAP standard there is no need to carry forward the balances as the system will do a virtual carry forward into next year opening without creating any FI documents.
    If your business scenario demands then you can use the transaction code F-02 for posting a carry forward balances, this will not effect any of your balances but only creates a FI document.
    If your R3 version is SAP ECC5 or 6 then use the transaction code FAGLGVTR

  • How to enter serial number for sale order line  which is in shipped status

    Hi All,
    We have 2 different items which are defined as Serialized at Sale order issue at item definition.
    In one sale order,User has forgot to add serial number to one of the item at Ship confirm stage.
    He has entered serial number correctly to other item.
    Now the both Sale order lines are in Shipped status if we view them through Shipping>transactions.
    I am technical guy and new to OM.Could you please let me know the process to enter the serial number for the item to which user has missed it
    Thanks,
    Satya

    Hi Satya,
    Since the item is already shipped, you cannot enter serial number for this line.
    you have to enter serial numbers after pick confirm only.
    check this note
    How to Enter Serial Numbers in the Shipping Transactions Form [ID 1235403.1]
    As a workaround for the previous lines do RMA and try to receive the goods back to your subinventory.
    For all new transactions follow the above notes.
    Thanks
    -Arif.

  • Want to know how to check for new line character in text file

    Hi All,
    I`m trying to read data from text file. However I`m not sure whether the data is in 1st line or nth line. Now I`m trying to read the text from the readline. But if text is "" and not NULL then my code fails. So I want to know how to check for new line character and go to next line to find the data. Please help.
    Thanks
    static int readandwriteFile(Logger logger,String filepath){
              BufferedWriter out = null;
              BufferedReader in = null;
              File fr = null;
              int get_count = 0;
              try     {
              if(new File(filepath).exists())
              fr= new File(filepath);
                        System.out.println("FileName: "+fr);
                   if(fr != null){
    in = new BufferedReader(new FileReader(fr));
                             String text = in.readLine();
                             if(text != null){
                             get_count = Integer.parseInt(text);
                             in.close();
                             else{
                                  get_count = 0;
         else{                    
    out = new BufferedWriter(new FileWriter(filepath));
         out.write("0");
                out.close();
                   }          //Reading of the row count file ended.
              catch(Exception e) {
                   e.printStackTrace();
              finally {
                   try{               if (in != null) {
                             in.close();
              if (out != null) {
                             out.close();
              catch(Exception e) {
                        e.printStackTrace();
              return get_count;
         }

    You are calling the readline() only once which means you are reading only the first line from the file...
    Use a loop (Do-While preferably)
    do{
    //your code
    }while(text == "")

  • How to enter condition wise tax amount manually in MIR7 & MIRO?

    We have a PO with a tax code entered in it.
    but while parking invoice in MIR7, we want to enter condition wise tax amount manully which is different than calculated tax amount through tax code and subsequently we want the same manual tax amount to be displayed in MIRO also
    I tried to enter amount for each condition in 'Detail' screen of 'Tax' tab in MIR7,
    but at the time of simulating, amount calculated as per tax code is only shown and not the amount entered by me
    'Calculate Tax' checkbox is not selectd in this case.
    Can anybody tell me how to enter condition wise tax amount manully in MIR7 & MIRO and post an accounting entry with this manually entered tax amount?

    Hi,
    i checked their is no unplanned delivery cost and in FV13 tax is 12.5%. In FTXP No Tax Percent rates.
    Regards
    Mahesh

  • How to enter two different ED% in J1ID

    Hi All,
    For a single material code which is having two different ED%, how to enter Exceptional ED% in transaction code J1ID.
    For ex: Material no. XYZ is procured with material type 123 and 789 which is having different ED% of 8.13% and 8.14%.
    Regards,
    Ram

    There cannot be two different material type for same material code.
    Pl check & confirm.
    Regards
    Bhavesh Mistry

  • How to enter an account assignment category for a material.

    Hi guys:
       I am facing following error prompt,please tell me how to enter an account assignment category for a material.
    thanks
    Account assignment mandatory for material 0000000N6451 (enter acc. ***. cat.)
    Message no. ME062
    Diagnosis
    There is no provision for value-based inventory management for this material type in this plant. Account assignment is thus necessary.
    Procedure
    Please enter an account assignment category.

    HI Shyam :
    Go to transaction type OMS2. Check whether the material type u are using is ticked for Value update.
    If not,
    a. Use a different material type
    b. or Use an account assignment category.
    How to use B,that is hot to enter an account assignment cateogory

  • How to enter the values in JTable in runtime

    how to enter the values in JTable in runtime

    Basically you need a vector of vectors or an array of arrays. Example (off the top of my head):
    With Arrays
    String[] cols = { "colone", "coltwo", "colthree", "colfour", "colfive" };
    String[] numbers = { "one", "two", "three", "four", "five" };
    String[] letters = { "A", "B", "C", "D", "E" };
    String[][] data = { numbers, letters };
    //make sure that the table has a scroll pane wrapped around it otherwise the header is not displayed
    JScrollPane scroll = new JScrollPane(new JTable(data, cols));
    With Vectors
    Vector cols = new Vector();
    cols.addElement("colone");
    cols.addElement("coltwo");
    cols.addElement("colthree");
    cols.addElement("colfour");
    cols.addElement("colfive");
    Vector numbers = new Vector();
    numbers.addElement("one");
    numbers.addElement("two");
    numbers.addElement("three");
    numbers.addElement("four");
    numbers.addElement("five");
    Vector letters = new Vector();
    numbers.addElement("A");
    numbers.addElement("B");
    numbers.addElement("C");
    numbers.addElement("E");
    numbers.addElement("F");
    Vector data = new Vector();
    data.addElement(numbers);
    data.addElement(letters);
    //make sure that the table has a scroll pane wrapped around it otherwise the header is not displayed
    JScrollPane scroll = new JScrollPane(new JTable(data, cols));The array or vector can be easily populated at runtime.
    Regards
    Riz

  • How to Enter multiple inputs at a time in Form or Table

    Hi,
    I have one doubt in Webdynpro with java. How to enter multiple inputs at a time?
    For Exam My requirement is we will take employee details node under node empid, name, sal  etc some attributes is here
    Client asking like this enter multiple inputs at a time that data will saved in ECC System.
    1.     By using form how can enter enter multiple inputs at a time I donu2019t this so I will take table(here I will select input fileds). If any possible in form also tell me how I can enter multiple inputs at a time.
    In table suppose 6 rows available So He will enter
                             empid, name, sal  ,firstname, last Name
                             empid, name, sal  ,firstname, last Name
                             empid, name, sal  ,firstname, last Name 
    Like 6 time Click Submit. That data will save in ECC.
    So I was taken table. But in that Table only first row will be editable. I want all 6 will editable that time he will put data in rows then click on submit.
    How to editable these remaining rows? if u have any documents pls send me.
    Regards
    Vijay Kalluri

    Dear Vijay,
    To enter multiple inputs in a table and to make the other rows editable you have to provide that node with initial values.
    by initial values I mean you have to make that much space in your table node.
    For example the name of Node is  yourNode & you have empid, name, sal ,firstname, last Name
    attributes in that node, and you have to make 6 rows editable.
    Then, simply write this code in you wdDoinit() method of your view controller.
    IPrivateYourView.IYourNodeElement e ;
    for(int i = 0 ; i < 6 ; i++ )
    e = wdContext.nodeYourNode().createYourNodeElement();
    e.setAttributeValue("empid" , "") ;
    e.setAttributeValue("name" , "") ;
    e.setAttributeValue("sal" ,  "") ;
    e.setAttributeValue("firstname" , "") ;
    e.setAttributeValue("lastname" , "") ;
      wdContext.nodeOverTimeEnty().addElement(e) ;
    Change YourView with your view name & YourNode with your node name.
    If you have any problem in doing this you can revert back.
    Hope it helps!!
    Warm Regards
    Upendra Agrawal

Maybe you are looking for

  • Data Sources error:[Macromedia][SQLServer JDBC Driver]No more data available to read.

    I have just set up the developer edition coldfusion and a standard SQL Server. When trying to set up a datasource i recieve the following error:  [Macromedia][SQLServer JDBC Driver]No more data available to read. I have no clue what this means. I hav

  • Contracts - 'Document still being processed in the background; try again la

    Hello, When trying to make adjustments to multiple contracts we are receiving the error message 'Document is still being processed in the background; try again later.'  We have tried again later to no effect. Ultimately, this means that these contrac

  • Wrong payment transaction

    To whom it may concern, Recently I received a money transaction document from my bank(ALPHA) in Greece, which indicate that Skype has charged me two times of 19.80 US$ in 04/12/2014 and in 01/03/2015 without my approvals. Noting these wrong transacti

  • Account assignment category for purchasing document

    Folks, I have created a new document type and I would only allow 1 specific account assignment category to be choosen. As far as I know I am only able to set the permissable item categories. Regards, MdZ

  • Photos From iPod to New Computer

    I need to know how to get the photos from my ipod on to my new computer. I have Windows XP and do not have iPhoto or Image Capture. I haven't found a place to download eitehr program. If anyone else has experienced this problem and has a solution ple