Array Struct

This is a discussion on Array Struct within the C Programming forums, part of the General Programming Boards category; in my .c file i have a struct atop of the program defined as follows: Code: #define MAX 10 int ...

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    12

    Array Struct

    in my .c file i have a struct atop of the program defined as follows:
    Code:
    #define MAX 10
    int curtab;
    
    static struct tab {
    	int count;
    	int use;
    } tab[MAX];
    with the initial function following it like so:
    Code:
    int tab_create(int init_count)
    {
           int i;
           for(i=0; i < MAX; i++)
    	{
    		if(tab[i].use != 1)
    		{
    			tab[i].use = 1; /* true */
    			tab[i].count = init_count;
    			curtab = i;
    			i = MAX; /* break */
    		}
    	}
           return (curtab);
    }
    but I find I receive a Seg-Fault error at
    Code:
    if(tab[i].use != 1)
    Why does this occur?
    Last edited by micmac700; 12-13-2006 at 10:17 AM.

  2. #2
    Registered User
    Join Date
    Nov 2006
    Posts
    176
    you sure thats where the problem is happening?

    one thing you should do, is make sure those sturct values are initialized before you test them against 1. unlless this is in some initialization funtion. We're gonna need to see more

  3. #3
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    also there is a logical problem - what will fuction return if all tabs are used?
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  4. #4
    Registered User
    Join Date
    Nov 2006
    Posts
    176
    your posts look scarier with Posts: 666 vart

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 12-03-2008, 03:10 AM
  2. Fixing my program
    By Mcwaffle in forum C Programming
    Replies: 5
    Last Post: 11-05-2008, 03:55 AM
  3. Replies: 16
    Last Post: 10-29-2006, 05:04 AM
  4. Array of struct pointers - Losing my mind
    By drucillica in forum C Programming
    Replies: 5
    Last Post: 11-12-2005, 11:50 PM
  5. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 05:15 AM

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