Sponsored Content
Top Forums Programming How to accept multiple lines input from User in C? Post 302528387 by AAKhan on Tuesday 7th of June 2011 06:01:42 AM
Old 06-07-2011
How to accept multiple lines input from User in C?

Hi
I want to accept multiple lines input with spaces from User and i have a working code like this.
Code:
char sRes[2000];
char sReq[1000];
 printf("Please enter request:");
 scanf("%[^\n]",sReq);           /* Accept the input from user */
 
 printf("\nPlease enter response:");
 scanf("%[^\n]",sRes);

but the problem is "sReq" is accepting the input but "sRes" is not accepting. If i change the second scanf to scanf("%s",sRes); it is accepting input but not input with spaces.
Why? What's the reason? How to solve this?
Thanks

---------- Post updated at 05:01 AM ---------- Previous update was at 03:47 AM ----------

HI
Hurray! I got the answer.
Thanks

Last edited by pludi; 06-07-2011 at 07:23 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Accept user input - only numbers

I have a situation where I want the user to enter only numbers in response to a READ command. I have some validation to restrict the number to be between 1 and 12, but if the user type in some characters the script echoes some error message and goes to the next command. Below is a snippet of the... (1 Reply)
Discussion started by: pvar
1 Replies

2. Shell Programming and Scripting

How to prompt for input & accept input in ONE line

hi, am a new learner to shell programming. i have a script which will prompt for user to key in their name & display their name afterwards. script ===== echo "Pls enter your name:" read name echo "Your name is $name." output ===== Pls enter your name: Bob Your name is Bob. what... (2 Replies)
Discussion started by: newbie168
2 Replies

3. UNIX for Dummies Questions & Answers

accept user input?

how would i accept user input from the keyboard? (2 Replies)
Discussion started by: JamieMurry
2 Replies

4. Shell Programming and Scripting

How to accept multiple input in a same variable

Hi All, I am trying to write a script in which I need to accept multiple value in the same variable. The case Is that I have put a FOR loop and inside the FOR loop I am accepting a variable value. And I require all the values which gets inputted in the variable. To be... (5 Replies)
Discussion started by: rahulmittal87
5 Replies

5. Shell Programming and Scripting

SQL PLUS Command 'ACCEPT' is not waiting for user input with sh shell script

Dear All, The sqlplus 'Accept' command is not waiting for user input when I include the command within a shell script. Note: The 'Accept' command is working fine if I execute it in a SQLPLUS Prompt. Please fins the below sample script which i tried. SCRIPT: -------- #!... (4 Replies)
Discussion started by: little_wonder
4 Replies

6. Shell Programming and Scripting

Capturing multiple values from user input

Hello, I need to capture multiple values from user input and do not know how to do it. I'm writing a script to delete old files, but want to give the option to keep some by asking the user. This is what my output looks like... Old files to be deleted... 1 file1 2 file2 Then this bit of... (3 Replies)
Discussion started by: jrymer
3 Replies

7. Shell Programming and Scripting

Shell script to accept user input on the fly

I want a shell script that accepts user input simultaneously when performing other tasks. Example: A shell script should echo some messages on the console and when the user presses some keys it should respond to that action. say, when user presses the key A - more information should be printed... (2 Replies)
Discussion started by: Arun_Linux
2 Replies

8. Shell Programming and Scripting

Perl : accept multiple user entered command line arguemnts

I am trying to create a script that will accept multi input from the user (really just me), then execute those command on a remote device. My question is if the I enter "No" at the confirmation point "Are these statements correct y or n ?", what is the best way to go back and start over ? I... (3 Replies)
Discussion started by: popeye
3 Replies

9. Programming

Separate input buffer into multiple lines

Hi All I have a very tricky problem, not able to solve it. Hence asking this question. I have a code portion like this - int parse_msg(in_buf,line1,line2,sccs_line) char in_buf; char line1; char line2; char sccs_line; { .... (void)fprintf(trace_fp,"parse_msg1 in_buf = %s \n",... (0 Replies)
Discussion started by: nsinha
0 Replies

10. Shell Programming and Scripting

Removing multiple lines from input file, if multiple lines match a pattern.

GM, I have an issue at work, which requires a simple solution. But, after multiple attempts, I have not been able to hit on the code needed. I am assuming that sed, awk or even perl could do what I need. I have an application that adds extra blank page feeds, for multiple reports, when... (7 Replies)
Discussion started by: jxfish2
7 Replies
curs_scanw(3CURSES)					     Curses Library Functions					       curs_scanw(3CURSES)

NAME
curs_scanw, scanw, wscanw, mvscanw, mvwscanw, vwscanw - convert formatted input from a curses widow SYNOPSIS
cc [ flag ... ] file ... -lcurses [ library ... ] #include <curses.h> int scanw(char *fmt, /* arg */ ...); int wscanw(WINDOW *win, char *fmt, /* arg */ ...); int mvscanw(int y, int x, char *fmt, /* arg */ ...); int mvwscanw(WINDOW *win, int y, int x, char *fmt, /* arg */...); int vwscanw(WINDOW *win, char *fmt, va_list varglist); DESCRIPTION
The scanw(), wscanw(), and mvscanw() routines correspond to scanf() (see scanf(3C)). The effect of these routines is as though wgetstr() were called on the window, and the resulting line used as input for the scan. Fields which do not map to a variable in the fmt field are lost. The vwscanw() routine is similar to vwprintw() in that it performs a wscanw() using a variable argument list. The third argument is a va_list, a pointer to a list of arguments, as defined in <varargs.h>. RETURN VALUES
vwscanw() returns ERR on failure and an integer equal to the number of fields scanned on success. Applications may interrogate the return value from the scanw, wscanw(), mvscanw(), and mvwscanw() routines to determine the number of fields which were mapped in the call. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |MT-Level |Unsafe | +-----------------------------+-----------------------------+ SEE ALSO
curs_getstr(3CURSES), curs_printw(3CURSES), curses(3CURSES), scanf(3C), attributes(5) NOTES
The header <curses.h> automatically includes the headers <stdio.h> and <unctrl.h>. SunOS 5.11 31 Dec 1996 curs_scanw(3CURSES)
All times are GMT -4. The time now is 07:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy