LinuxQuestions.org
Visit Jeremy's Blog.
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 01-10-2017, 11:25 AM   #1
killingthemonkey
Member
 
Registered: Mar 2011
Location: Winston-Salem, NC
Distribution: Fedora, CentOS, Linux Mint
Posts: 259

Rep: Reputation: 24
C, Display an Array of Integers


NOTE: It's amazing what difference a > makes when you need a <.

Code:
/* TenNumbers.c */
 
/*
    Take input from user
    Store user input in a single dimension array
    Display a menu to sort and print in ascending, or descending order
*/
#include <stdio.h>
#include <stdlib.h>
 
int main()
{
    int numbers[10];
    int x, y, swap;
    int iSelection;
 
    for(x = 0; x < 10; x++)
    {
        system("clear");
        printf("\nPlease enter a number: ");
        scanf("%d", &numbers[x]);
    }

    for(x = 0; x > 10; x++)
    {
        printf("%d | ", numbers[x]);
    }
 
    return 0;
} // End main function
OK, there it is. Ignore the unused variables for the moment. They're going to be used in sorting the array later. I want to display it. This code compiles without a complaint, but when I run it, I get no output.

Thanks,
Doug

EDIT: I just ran it through the C compiler at TutorialsPoint... Same issue.

EDIT Redux: The issue seems to be with my output loop. I replaced the input loop with hard code and it still seemed to work.

Code:
    printf("\nPlease enter a number: ");
    scanf("%d", &numbers[0]);
    printf("\nPlease enter a number: ");
    scanf("%d", &numbers[1]);
    printf("\nPlease enter a number: ");
    scanf("%d", &numbers[2]);
    printf("\nPlease enter a number: ");
    scanf("%d", &numbers[3]);
    printf("\nPlease enter a number: ");
    scanf("%d", &numbers[4]);
    printf("\nPlease enter a number: ");
    scanf("%d", &numbers[5]);
    printf("\nPlease enter a number: ");
    scanf("%d", &numbers[6]);
    printf("\nPlease enter a number: ");
    scanf("%d", &numbers[7]);
    printf("\nPlease enter a number: ");
    scanf("%d", &numbers[8]);
    printf("\nPlease enter a number: ");
    scanf("%d", &numbers[9]);

Last edited by killingthemonkey; 01-10-2017 at 11:40 AM.
 
Old 01-10-2017, 11:37 AM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,702

Rep: Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896
Hint...

Code:
 for(x = 0; x > 10; x++)
 
Old 01-10-2017, 11:43 AM   #3
killingthemonkey
Member
 
Registered: Mar 2011
Location: Winston-Salem, NC
Distribution: Fedora, CentOS, Linux Mint
Posts: 259

Original Poster
Rep: Reputation: 24
Smile

I think I was fixing it while you posting. Talk about a brick to the head.

Thank you.

Quote:
Originally Posted by michaelk View Post
Hint...

Code:
 for(x = 0; x > 10; x++)

Last edited by killingthemonkey; 01-10-2017 at 11:50 AM.
 
  


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
[SOLVED] array can't check for user input duplicate integers andrew.comly Programming 8 03-25-2015 07:43 AM
append integers until total is x integers razorcbl Linux - Newbie 7 03-12-2014 02:29 PM
Display Array of Strings with White Spaces coffee arabia Linux - Newbie 3 10-02-2010 12:48 AM
Pointer to array of integers thelink123 Programming 7 08-24-2009 08:15 PM
Convert binary to integers and double array in C Jose_Manu Programming 1 01-05-2007 07:14 AM

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

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