Re: Structures, Pointer and gets
From: Richard Heathfield (dontmail_at_address.co.uk.invalid)
Date: 11/15/03
- Next message: Nudge: "Re: Use of do...while(0) in ASSERT macro"
- Previous message: Richard Heathfield: "Re: Structures, Pointer and gets"
- In reply to: RAiN: "Re: Structures, Pointer and gets"
- Next in thread: RAiN: "Re: Structures, Pointer and gets"
- Reply: RAiN: "Re: Structures, Pointer and gets"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 15 Nov 2003 16:13:30 +0000 (UTC)
RAiN wrote:
> Well first if you want something to be sent back your function mustnt be
> void or you can use it void but call by reference (pass the address)
There is no such thing as call by reference in C.
As it happens, he's using an array, so it's a moot point anyway (since the
name of an array decays into a pointer to its first element).
> Cause as you probably know if you pass a variable by value, it creates a
> copy which dies at the end of the called function itself: so or return
> value or work on the address.
>
> Second, in the ReadStudent prototype you should declare an array of 10
> elements. Arrays are just pointers for C.
Not true. If it were true, arrays would have the same size as pointers, and
they don't (except by coincidence).
> When you pass an array to a
> function in the end you just pass the location memory of the first
> element, then you access to the others with pointers arithmetics.
That, at least, is correct.
<snip>
> void ReadStudents(student *myStud){
>
> printf("Plz insert your name: ");
> gets(myStud->Name);
> }
Undefined behaviour, guaranteed. Quite apart from using the gets() function
(which is severely broken), you forgot to reserve any storage for Name.
-- Richard Heathfield : binary@eton.powernet.co.uk "Usenet is a strange place." - Dennis M Ritchie, 29 July 1999. C FAQ: http://www.eskimo.com/~scs/C-faq/top.html K&R answers, C books, etc: http://users.powernet.co.uk/eton
- Next message: Nudge: "Re: Use of do...while(0) in ASSERT macro"
- Previous message: Richard Heathfield: "Re: Structures, Pointer and gets"
- In reply to: RAiN: "Re: Structures, Pointer and gets"
- Next in thread: RAiN: "Re: Structures, Pointer and gets"
- Reply: RAiN: "Re: Structures, Pointer and gets"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|