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-14-2010, 07:11 PM   #1
thehollow89
LQ Newbie
 
Registered: Mar 2010
Posts: 14

Rep: Reputation: 0
C Program to get input of array and output it


I am creating a 15 integer array which is input from the user and outputted for the.

Ex.
Enter the array values: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Your values are: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

Code:
#include <stdio.h>

/* function main begins program execution */
int main()
{
int value[15];
while(true)
{
printf( "Enter the array values: " ); //prompt
scanf( "%d", &value); //reads integers
printf("Your values are: ");
for(int i=0; i<15; i++)
{
printf("%d", value[i]);
}
}
return 0;
}
 
Old 08-14-2010, 07:19 PM   #2
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by thehollow89 View Post
I am creating a 15 integer array which is input from the user and outputted for the.

Ex.
Enter the array values: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Your values are: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

Code:
Code:
#include <stdio.h>

/* function main begins program execution */
int main()
{
    int value[15];
    while(true)
    {
        printf( "Enter the array values: " ); //prompt
        scanf( "%d", &value); //reads integers
        printf("Your values are: ");
        for(int i=0; i<15; i++)
        {
            printf("%d", value[i]); 
        }
    }
    return 0;
}
  1. Use CODE tags;
  2. What is the exact question ?
  3. What did you do to debug ?
  4. Did you read 'man 3 scanf' and if yes, based on which lines of the manpage you wrote "scanf( "%d", &value); //reads integers" ?
 
Old 08-14-2010, 07:57 PM   #3
mrshanim
Member
 
Registered: Aug 2009
Posts: 30

Rep: Reputation: 16
Printing output values should be after the end of while loop as

main()
{
while(cond)
{
"enter values(Input)"
}

"Print all values (Output)"
}
 
Old 08-14-2010, 08:11 PM   #4
thehollow89
LQ Newbie
 
Registered: Mar 2010
Posts: 14

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by mrshanim View Post
Printing output values should be after the end of while loop as

main()
{
while(cond)
{
"enter values(Input)"
}

"Print all values (Output)"
}
But how can I do the input on one line that way? Wouldn't it require me to hit return after each value for all 15 values? I wanna enter all 15 integers (separated by white space) on one line.
 
Old 08-15-2010, 05:06 AM   #5
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by thehollow89 View Post
But how can I do the input on one line that way? Wouldn't it require me to hit return after each value for all 15 values? I wanna enter all 15 integers (separated by white space) on one line.
I am asking you again: did you read 'man 3 scanf' ? The answer is there.
 
  


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
bash: use file as input into array, parse out other variables from array using awk beeblequix Linux - General 2 11-20-2009 10:07 AM
Connecting both standard input and output to another program so that they can interac eantoranz Linux - Software 7 06-28-2009 07:03 PM
how to show input and output of a program on the terminal divin Linux - Software 1 03-25-2005 12:19 AM
Exercise 1-9. Write a program to copy its input to its output, replacing each string zombi3 Programming 3 12-21-2003 02:28 AM
Getting random array input. vexer Programming 2 04-29-2003 11:25 PM

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

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