Thread: structs

  1. #16
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Quote Originally Posted by bazzano
    menu->headCategory->headItem->prices[3]->dollars = 0
    thats how it is but i get a seg fault
    You said that NUM_PRICES is declared as 3 so prices[3] is past the array-bounds
    Kurt

  2. #17
    Musicman - Canora
    Join Date
    Aug 2005
    Location
    Melbourne
    Posts
    252
    but if i say that prices[3] how am i goin past the array bounds when dollars=0

  3. #18
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    There are only 3 prices.
    prices[3] is the 4th.
    Kurt

  4. #19
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    when u say prices[3]. three array elements are declared of type struct .... where elem1 is refrences by prices[0] all array elements starts from 0. so when u say prices[3]. three elements are declared prices[0], prices[1], prices[2]. when u say prices[3] it is out of boundary and when accessing the dollor which u cant do will get u SEGFAULT

    ssharish2005

  5. #20
    Registered User 00Sven's Avatar
    Join Date
    Feb 2006
    Posts
    127
    If you declared prices as prices[3] There would be something in prices[0], prices[1], and prices[2]. The counting starts at 0 not 1. So anything beyond prices[2] gets you a seg fault.
    ~Sven
    Windows XP Home Edition - Dev-C++ 4.9.9.2
    Quote Originally Posted by "The C Programming Language" by Brian W. Kernignhan and Dennis M. Ritchie
    int fflush(FILE *stream)
    On an output stream, fflush causes any buffered but unwritten data to be written; On an input stream, the effect is undefined. It returns EOF for a write error, and zero otherwise. fflush(NULL) flushes all output streams.
    board.theprogrammingsite.com

  6. #21
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    Yet another programmer who doesn't know how to count from 0...
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

  7. #22
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    prices[somenumberhere] is not a pointer array of type PriceType; its just a normal array. -> is used when access the struct data members using pointer. as its a normal array u need to access the data members uisng . operator.

    i am suprised dint the compiler give any error about thus telling "invalid type argument of â->â
    "

    ssharish2005

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Creating array of structs
    By knirirr in forum C++ Programming
    Replies: 12
    Last Post: 06-18-2008, 08:30 AM
  2. Multidimentional structs + memcpy() == FAIL
    By Viper187 in forum C Programming
    Replies: 8
    Last Post: 06-18-2008, 02:46 AM
  3. packed structs
    By moi in forum C Programming
    Replies: 4
    Last Post: 08-20-2002, 01:46 PM
  4. ArrayLists + Inner Structs
    By ginoitalo in forum C# Programming
    Replies: 5
    Last Post: 05-09-2002, 05:09 AM
  5. Searching structs...
    By Sebastiani in forum C Programming
    Replies: 1
    Last Post: 08-25-2001, 12:38 PM