LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-04-2004, 12:25 AM   #1
blackzone
Member
 
Registered: Jun 2004
Posts: 256

Rep: Reputation: 30
scanf


Below is a simple code usnig scanf
===============================
char buffer[100];

while(1){
printf("> ");
scanf("%s", buffer);
}
================================
which will get input. and print ">" and wait another.

The problem I have is if I press "Enter" without any input.
It'll just halt there untill I do actually put some input and press "Enter".

Which works different as what I want. I thought if I press "Enter" without any input, buffer will just store "\0";
=================================

Anyway to modify it?
 
Old 08-04-2004, 01:50 AM   #2
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Try this:

Code:
        char buffer[100];
        while(1)
        {
                printf(">  ");
                fgets(buffer, 99, stdin);
        }
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
scanf question exvor Programming 5 07-24-2005 04:36 PM
problem with scanf fssengg Programming 3 03-29-2005 04:27 AM
scanf question jnusa Programming 4 01-07-2005 09:04 AM
scanf help homerz Programming 2 11-11-2003 05:48 AM
Is it safe to use scanf for anything?? purpleburple Programming 5 07-03-2002 06:19 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:06 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration