Arrays - used for remembering integers

This is a discussion on Arrays - used for remembering integers within the C Programming forums, part of the General Programming Boards category; I have a problem. I want to store an integer to an array which is obtained from an input. Code: ...

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    6

    Arrays - used for remembering integers

    I have a problem. I want to store an integer to an array which is obtained from an input.

    Code:
    scanf("%d",&integer);
    eg if the user enters 1234

    it will store it in arrays as

    integer1 - 1
    integer2 - 2
    integer3 - 3
    integer4 - 4


    sorry for the newbie question. >_<

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,531
    No, it will store 1234 in that single integer.

    int array[4];

    needs a for loop to call scanf 4 times.
    scanf("%d", &array[index] );
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Is this a class assignment?

    You might find some ideas here...

    converting a string to an array

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Storing integers from file into arrays???? please help
    By adzza69 in forum C++ Programming
    Replies: 5
    Last Post: 09-11-2004, 12:28 AM
  2. reading integers into arrays from text files
    By c_beginner in forum C Programming
    Replies: 6
    Last Post: 08-05-2004, 11:42 AM
  3. integers storing as symbols in arrays
    By rjcarmo in forum C++ Programming
    Replies: 4
    Last Post: 05-19-2003, 01:17 AM
  4. Adding arrays of integers in a node struct
    By emilyashu in forum C Programming
    Replies: 7
    Last Post: 04-26-2003, 06:19 PM
  5. Multipling Integers in Arrays
    By Rvaren in forum C++ Programming
    Replies: 10
    Last Post: 10-14-2002, 03:13 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21