Thread: How to read a line and put in cahr variable

  1. #1
    Registered User
    Join Date
    Jan 2010
    Posts
    50

    How to read a line and put in cahr variable

    Hi

    I want to take three inputs from user. First one is of integer, second one is a word and third one is a sentence. The problem is when i am taking third input it is taking only first word of the line.How i can take entire line as input. I am using following code

    Code:
    while(another=='Y')
    {
    printf("\n Enter schedule id,schedule name and schedule description\n");
    scanf("%d %s %31s",&schinf.sch_id,schinf.sch_name,schinf.sch_dsc);
    fwrite(&schinf,sizeof(schinf),1,fp);
    printf("\nWould you like to enter another record?\n");
    while((another=getchar())!='\n');
    another=getchar();
    
    }
     Thnaks in advance
    
    Sas

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,794
    replace %31s with %31[^\n]
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. read amount of columns per line
    By andone in forum C Programming
    Replies: 12
    Last Post: 12-01-2006, 01:39 AM
  2. I need help as soon as possible.
    By hyrule in forum C++ Programming
    Replies: 7
    Last Post: 11-09-2005, 05:49 PM
  3. how do you read a whole line of text from a txt file
    By themexican in forum C++ Programming
    Replies: 3
    Last Post: 10-18-2005, 09:17 AM
  4. read from .txt file & put into array?
    By slow brain in forum C Programming
    Replies: 6
    Last Post: 02-25-2003, 05:16 AM
  5. Debugging link error
    By bubux in forum C Programming
    Replies: 5
    Last Post: 07-06-2002, 02:19 PM