Thread: array probs

  1. #1
    confusedaalottt
    Guest

    array probs

    i'm trying to input data in to an array. problem is i need to be able to access the function and enter data while the incrementer is incremented. To get rid of junk values in the indexer i've assigned it 0. Problem is the array resets itself everytime i access the function. If i dont assign a value to the indexer it shows data that makes no sense....does anyone know a way around this so that the array doesnt always automatically reset but at the same time doesnt show junk? I need to access the function via a menu but i need previous entries entered to show up without the same array area being constantly overwritten. Any help appreciated!

    thanks

    Code:
    void example (void);
    
    int main (void){
     int key;
    
     printf("\n***********MENU**********");
     printf("press 1 to view example");
      key=getch();
     
        if(key==1){
              example();
      }else 
              printf("\nerror");
      getch();
    }
    
    void example (void){
    int i; /*indexer*/
    i=0; /*initialised*/ <---------this presents a problem as dont want
                                               it to initialise evertime i enter data
                                               as array resets. I only want it to
                                               reset if i exit the program

  2. #2
    Casual Visitor
    Join Date
    Oct 2001
    Posts
    350
    static int i=0; ?
    I haven't used a compiler in ages, so please be gentle as I try to reacclimate myself. :P

  3. #3
    confusedaalottt
    Guest
    thanks!!! i owe u

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>static int i=0;
    Or just:
    >>static int i;
    as static variables are initialised to 0 by default.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. from 2D array to 1D array
    By cfdprogrammer in forum C Programming
    Replies: 17
    Last Post: 03-24-2009, 10:33 AM
  2. Replies: 7
    Last Post: 11-25-2008, 01:50 AM
  3. 1-D array
    By jack999 in forum C++ Programming
    Replies: 24
    Last Post: 05-12-2006, 07:01 PM
  4. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 04:15 AM
  5. two dimensional dynamic array?
    By ichijoji in forum C++ Programming
    Replies: 6
    Last Post: 04-14-2003, 04:27 PM