LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 10-26-2010, 09:03 AM   #1
Abid Malik
LQ Newbie
 
Registered: Sep 2010
Posts: 25

Rep: Reputation: -1
Thumbs down scanf challenge


Hello!

here is my programm in "C" language.

#include <stdio.h>

void getvalue(int *value)
{
int n;
n = scanf("%d", value);

}

int main()
{
int num;
getvalue(&num);

return 0;
}

what did it actually do, it take a number and read it through key board. if we press just "enter key" and give no input it ignore the "enter key" and continuously asks for input. I wants that it should leave the command and get back to main. i mean if we press enter it should not ask again for input again.
 
Old 10-26-2010, 09:13 AM   #2
soppy
Member
 
Registered: Mar 2008
Location: In your head!
Distribution: Arch Linux
Posts: 165
Blog Entries: 1

Rep: Reputation: 28
Why do you need another function to do this?? That's terrible programming as it uses too much memory. Just have scanf in your main function. And the problem with your program is that your getvalue function doesn't return a value to the main function. I suggest you go to this website to learn C.

http://www.cprogramming.com/tutorial.html
 
Old 10-26-2010, 10:58 PM   #3
Manjunath1847
Member
 
Registered: Mar 2007
Posts: 44

Rep: Reputation: 16
Quote:
Originally Posted by Abid Malik View Post
I wants that it should leave the command and get back to main. i mean if we press enter it should not ask again for input again.
Then dont use scanf. Scanf call will block till u give a input. Try getchar() or getch() or gets()
 
  


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 twisted!! man s Programming 5 03-11-2010 07:50 AM
Using scanf in c on doubles mkrems Programming 2 04-28-2008 07:10 PM
scanf anomaly barunparichha Linux - Newbie 8 08-13-2006 11:03 AM
scanf blackzone Programming 1 08-04-2004 01:50 AM
scanf help homerz Programming 2 11-11-2003 05:48 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:00 AM.

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