c field - print after adding

This is a discussion on c field - print after adding within the C Programming forums, part of the General Programming Boards category; Hi there. I have just started doing C, and already got to first full stop :S. Problem is next: I ...

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    2

    Unhappy c field - print after adding

    Hi there. I have just started doing C, and already got to first full stop :S.

    Problem is next:

    I have to define a field of, lets say 5 elements, and then print it. And also I have to define function that will add element to beggining of the field and to the end of the field. And after that I have to print the "new" bigger field. And that is the problem. If I define field as
    Code:
    int field[5]
    I dont know how to print field after adding elements to it. I know that I have to do something with [5], but I dont know.

    Can anyone help
    Last edited by celebro; 03-25-2011 at 10:51 AM.

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    Use a for loop:
    Code:
    int i;
    int field[5];
    for(i = 0; i < 5; i++)
    {
        // Do something with field[i]
    }
    bit∙hub [bit-huhb] n. A source and destination for information.

  3. #3
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,832
    You have to define another field2[20] for example. Then move some values into the first few elements, followed by the elements in field[], followed by some more elements for then end. Then print out field2.

  4. #4
    Registered User
    Join Date
    Mar 2011
    Posts
    2
    works for me, tyvm

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Looking for a little assistance with item class design...
    By Raigne in forum Game Programming
    Replies: 5
    Last Post: 10-22-2008, 08:55 AM
  2. add/remove a field to structure
    By andone in forum C Programming
    Replies: 2
    Last Post: 03-26-2007, 12:01 AM
  3. Adding nodes to a linked list
    By bluescreen in forum C Programming
    Replies: 4
    Last Post: 11-09-2006, 12:59 AM
  4. SVN Import Causes Crash
    By Tonto in forum Tech Board
    Replies: 6
    Last Post: 11-01-2006, 02:44 PM
  5. Please critique and suggest improvements for parser
    By Queue in forum C Programming
    Replies: 14
    Last Post: 09-28-2006, 08:28 PM

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