Thread: insert

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    3

    insert

    Hi,
    I want to create a program and insert some numbers into an array
    for example:
    > test1 //start the program
    2 4 6 5 3 20 30 60 50 40 //insert thoes values into array in the program

    how can i do it?

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    You've left out so many details I am unable to answer your question.
    Mainframe assembler programmer by trade. C coder when I can.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    You want to insert them by keyboarding them into the array?

    Code:
    int i, size_of_the_array;
    
    for(i = 0; i < size_of_ the_array; i++) {
      printf("\n Enter a number %d: ", i+1);
      scanf("%d", &array[i]);
    }
    Remember that all C arrays begin with array[0], and stop at array[size - 1]. So if your arrray has space for 10 items, the last number it can hold will be in array[9], not array[10].

  4. #4
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    Quote Originally Posted by nirnir26 View Post
    Hi,
    I want to create a program and insert some numbers into an array
    for example:
    > test1 //start the program
    2 4 6 5 3 20 30 60 50 40 //insert thoes values into array in the program

    how can i do it?
    Arrays
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

  5. #5
    Registered User
    Join Date
    Nov 2009
    Posts
    3

    I want to insert them with one scanf

    somthing more like:

    int i, size_of_the_array;

    printf("\n Enter a number %d: ", i+1);
    scanf("%d", &array[i]);
    // the input should be a lot of numbers with space between every two //
    so i dont think the scanf above will work... maybe to insert all the number into a string and then work on the string... or somthing else... im not sure....

    do u know how to do it?
    thnx.

  6. #6
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    Use loops for that purpose, as Adak has already explained.
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

  7. #7
    Registered User
    Join Date
    Oct 2009
    Location
    While(1)
    Posts
    377
    Quote Originally Posted by nirnir26 View Post
    somthing more like:

    int i, size_of_the_array;

    printf("\n Enter a number %d: ", i+1);
    scanf("%d", &array[i]);
    // the input should be a lot of numbers with space between every two //
    so i dont think the scanf above will work... maybe to insert all the number into a string and then work on the string... or somthing else... im not sure....

    do u know how to do it?
    thnx.

    Adak is correct what is the problem in gettin dude
    scanf will work exactly perfect apply your brain dude scanf is having %d it is depicting that its an int array.

    So it is not a string first of all

    for string Adak would have been used scanf("%s", &string);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. insert into binary tree question..
    By transgalactic2 in forum C Programming
    Replies: 32
    Last Post: 11-18-2008, 03:21 PM
  2. How to insert an item to a ListView
    By ysabelle in forum C++ Programming
    Replies: 2
    Last Post: 05-07-2007, 07:03 AM
  3. How to insert data to the top of exist text file?
    By ooosawaddee3 in forum C++ Programming
    Replies: 4
    Last Post: 08-16-2005, 08:08 AM
  4. Insert unique record into database
    By groorj in forum C Programming
    Replies: 4
    Last Post: 12-29-2004, 11:06 AM
  5. Replies: 1
    Last Post: 09-17-2001, 05:46 AM