LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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-14-2010, 02:31 PM   #1
thehollow89
LQ Newbie
 
Registered: Mar 2010
Posts: 14

Rep: Reputation: 0
C Program take multiple inputs same line


I want to be able to enter three integers as lengths of a triangle and store them in side1, side2 and side3 in the order they're entered.
Ex.
Enter the sides of the triangle: 3 4 5
stores 3 in side1
stores 4 in side2
stores 5 in side3

What is the correct format of doing so?

Code:
#include <stdio.h>

/* function main begins program execution */
int main()
{
int side1;
int side2;
int side3;
printf( "Enter the sides of the triangle: " ); //prompt
scanf( "%d", &side1, &side2, &side3 ); //reads integers
printf("Your sides are: ", side1, side2, side3);

return 0;
}
 
Old 08-14-2010, 02:48 PM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

Simple - you're 99.99% of the way there already:
Code:
#include <stdio.h>

/* function main begins program execution */
int main()
{
  int side1, side2, side3;
  printf( "Enter the sides of the triangle: " ); //prompt
  scanf( "%d %d %d", &side1, &side2, &side3 ); //reads integers
  printf("Your sides are: side1=%d, side2=%d, side3=%d\n", side1, side2, side3);

  return 0;
}
'Hope that helps .. PSM

Last edited by paulsm4; 08-14-2010 at 02:49 PM.
 
  


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
Create BASH script to process multiple inputs on read davisbase Linux - Newbie 5 05-26-2010 11:57 PM
shell script for a partial control over inputs to an external program njain Linux - Software 1 05-19-2010 07:57 PM
data type help needed and multiple inputs in single line shank.nikhil Programming 3 04-04-2009 08:04 PM
Automatic command line inputs at startup JamesNewbie Fedora 2 10-27-2006 06:07 PM
How to pass data to a console program with multiple inputs? juanbobo Programming 3 08-18-2005 06:39 PM

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

All times are GMT -5. The time now is 01:03 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