How to read a line and put in cahr variable

This is a discussion on How to read a line and put in cahr variable within the C Programming forums, part of the General Programming Boards category; Hi I want to take three inputs from user. First one is of integer, second one is a word and ...

  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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,424
    replace %31s with %31[^\n]
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

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, 12:39 AM
  2. I need help as soon as possible.
    By hyrule in forum C++ Programming
    Replies: 7
    Last Post: 11-09-2005, 04: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, 04:16 AM
  5. Debugging link error
    By bubux in forum C Programming
    Replies: 5
    Last Post: 07-06-2002, 02:19 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21