Re: Passing an array of struct to function



arnuld said:

I am passing an array of struct to a function to print its value. First
I am getting Segfaults and weired values. 2nd, is there any elegant way
to do this ?

/* Learning how to use an array of struct */


#include <stdio.h>
#include <stdlib.h>

enum { ARR_SIZE = 1 };

struct two_elem { char ch; char* word; };


void print_twoelem( struct two_elem*);


int main(void)
{

struct two_elem arr[ARR_SIZE];

If you're going to put two elements into this array, why do you define it
to have room for only one element?

The answer to your second question is "yes".

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
.



Relevant Pages

  • Re: Unsigned integers
    ... >> less efficient (albeit more elegant, of course) than "unrolled loops' ... And I'm with you that small data doesn't always, or even usually, mean fast code. ... Using a short int to save space is going to cost you some speed when the native word size is a long int. ...
    (microsoft.public.vb.syntax)
  • Re: sorting the input
    ... It Segfaults:(. ... One might infer that sorting is important. ... int readlines(char**, const int); ... int p_strcmp(const void* pv1, const void* pv2) ...
    (comp.lang.c)
  • Re: C99 IDE for windows
    ... arnuld said: ... the sign and one for the null terminator. ... To get the number of bits in an int. ... Athlon 64 3000+? ...
    (comp.lang.c)
  • Re: K&R2, exercise 6.4
    ... arnuld said: ... int* pi = arr; ... pointer as result ...
    (comp.lang.c)
  • bsearch script segfault
    ... I have a similar script that works fine, and now this simply segfaults. ... int compare_aliases{ ... struct aliasid* new_aliasid{ ...
    (comp.lang.c)