Thread: How to read multiple lines of input

  1. #1
    Registered User
    Join Date
    Aug 2012
    Posts
    33

    Angry How to read multiple lines of input

    Hi,

    All I want is read input(it can be multiples lines) from console till it encounters EOF character.how can I handle multiple lines of string under one var?

    Actually I tried to read
    while((c=getchar())!=EOF) but it not works

    Thanks,
    Veera
    Last edited by veera; 06-28-2015 at 12:41 PM.

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,793
    Quote Originally Posted by veera View Post
    but it not works
    This is terrible bug description

    1. Show your code
    2. Show your input data
    3. Explain what is the expected output
    4. Show the actual output
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    David J. Wheeler

  3. #3
    Registered User
    Join Date
    Aug 2012
    Posts
    33
    Quote Originally Posted by vart View Post
    This is terrible bug description

    1. Show your code
    2. Show your input data
    3. Explain what is the expected output
    4. Show the actual output
    Below is my problem. Input

    The first lines of the input is an integer N (1 <= N <= 1000). Next follows the input consisting of ASCII characters. The input is terminated by EOF character.
    Length of each word is less than 1024 and maximum number of words can be never more than 1024.

    Output

    The input reversed N times with at least a space/newline between any two words of your output.


    Example
    Input:
    2
    Fox jumps over the lazy dog.


    Output:
    .god .god yzal yzal eht eht revo revo spmuj spmuj xoF xoF



    Input:
    1
    It matters not how strait the gate,
    How charged with punishments the scroll.
    I am the master of my fate:
    I am the captain of my soul.

    Output:
    .luos ym fo niatpac eht ma I
    :etaf ym fo retsam eht ma I
    .llorcs eht stnemhsinup htiw degrahc woH
    ,etag eht tiarts woh ton srettam tI

  4. #4
    Registered User
    Join Date
    May 2015
    Posts
    90
    I think you missed:
    1. Show your code



  5. #5
    Registered User
    Join Date
    Jun 2015
    Location
    Delhi
    Posts
    35
    Lets say the file you have to read is T.txt, the methods for you to solve this problem is:

    Traverse the file, store the integer somewhere & while traversing insert each ASCII character into a doubly linked list and print it as many times the integer in starting of file is given using some manipulation - rest I hope you can try it yourself & Please look for a better solution too which doesn't include storage structure like linked list if possible.

    It will be better if you think this on your own - time consuming but worth gaining some experience.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. cin >> string // multiple lines
    By msshapira in forum C++ Programming
    Replies: 7
    Last Post: 05-27-2009, 04:39 AM
  2. read multiple lines from a file
    By YankeePride13 in forum C Programming
    Replies: 2
    Last Post: 11-10-2005, 10:30 PM
  3. recv multiple lines
    By TCM in forum Networking/Device Communication
    Replies: 11
    Last Post: 07-13-2004, 04:54 PM
  4. Macros with multiple lines
    By flipper2971 in forum C Programming
    Replies: 2
    Last Post: 11-03-2003, 09:30 PM
  5. Multiple lines on an Edit box
    By RubenJ in forum Windows Programming
    Replies: 3
    Last Post: 09-20-2001, 02:51 PM

Tags for this Thread