C prog: printing values from array of structures

Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
36 replies · 35K views
Your function should look like this:

PHP:
void print_name(struct pers_info record) {
    ...
}

And the code calling it should look like:

PHP:
for (int n=0;n<5;n++)
   print_name(arr[n]);

Passing a struct by value is no different than passing any other kind of variable by value.

- Warren
 
Physics news on Phys.org
print_names(struct pers_info arr[n]);

You don't need to include the type when passing an argument (except for type casts, which is not what's required here).
 
chroot said:
Your function should look like this:

PHP:
void print_name(struct pers_info record) {
    ...
}
record? Does that mean one of the individual structures I made? thanks. Record isn't a keyword is it?
 
When you create a function, you can call the variables it receives by any names you'd like. Even if the calling function referred to a hunk of data as arr[n], the called function can choose to call that incoming hunk of data anything it wants. In this case, I chose the word 'record' to refer to the variable being passed into the print_name function. It's not a reserved word in C, and means, well, nothing -- you can call it aStudent if you want, or theThingy, too.

- Warren