Article View: alt.comp.lang.learn.c-c++
Article #307Re: pass structure by reference / by value
From: Berend Meijer
Date: Sat, 26 Jan 2002 18:28
Date: Sat, 26 Jan 2002 18:28
72 lines
2701 bytes
2701 bytes
You are incrementing ttl in the wrong place. Try this.
Berend
void appRec(mystr *s1, int &ttl)
{
cout << "\nTotal in function: " << ttl;
strcpy(s1[ttl].id, "1000005");
strcpy(s1[ttl].name, "Minotaic");
ttl++;
int i=0;
for (i=0; i<ttl; i++)
{
cout << "\nStud ID fnt : " << s1[i].id;
cout << "\tName fnt : " << s1[i].name;
}
}
--
"EL" <lameddie@yahoo.com> wrote in message
news:a2um2g$1q1@imsp212.netvigator.com...
> Hi all,
>
> I want to pass a structure to my own function and change its value,
however
> i couldn't get the expected result. why?
>
> struct mystr
> {
> char id[7], name[21];
> };
>
> void appRec(mystr* , int&);
>
> void main()
> {
> mystr s[50];
> int i, j, b, ttl;
> char vid[7], bid[7];
>
> strcpy(s[0].id, "1000001");
> strcpy(s[0].name, "RobertHi");
> strcpy(s[1].id, "1000008");
> strcpy(s[1].name, "KawaiiNic");
>
> ttl = 2;
> appRec(s, ttl);
> for (i=0; i<ttl ; i++)
> {
> cout << "\nStud ID : " << s[i].id;
> cout << "\tName : " << s[i].name;
> }
>
> }
>
> void appRec(mystr *s1, int &ttl)
> {
> ttl++;
> cout << "\nTotal in function: " << ttl;
> strcpy(s1[ttl].id, "1000005");
> strcpy(s1[ttl].name, "Minotaic");
> int i=0;
> for (i=0; i<ttl; i++)
> {
> cout << "\nStud ID fnt : " << s1[i].id;
> cout << "\tName fnt : " << s1[i].name;
> }
> }
>
>
Technical Details
Message-ID:
<a2usgv$1v6j$1@scavenger.euro.net>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!newsfeeds.belnet.be!news.belnet.be!newsfeed00.sul.t-online.de!t-online.de!newsfeed.freenet.de!news2.euro.net!news.euronet.nl!not-for-mailReferences:
<a2um2g$1q1@imsp212.netvigator.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f8d38,d119aab9300bf461 X-Google-Attributes: gidf8d38,public X-Google-Thread: 109fba,d119aab9300bf461 X-Google-Attributes: gid109fba,public X-Google-Thread: 114592,d119aab9300bf461 X-Google-Attributes: gid114592,public X-Google-ArrivalTime: 2002-01-26 10:28:49 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!newsfeeds.belnet.be!news.belnet.be!newsfeed00.sul.t-online.de!t-online.de!newsfeed.freenet.de!news2.euro.net!news.euronet.nl!not-for-mail From: "Berend Meijer" <bmeijer@euronet.nl> Newsgroups: alt.comp.lang.learn.c-c++,borland.public.cpp.language,comp.lang.c++ Subject: Re: pass structure by reference / by value Date: Sat, 26 Jan 2002 18:28:55 -0000 Organization: EuroNet Internet Lines: 74 Message-ID: <a2usgv$1v6j$1@scavenger.euro.net> References: <a2um2g$1q1@imsp212.netvigator.com> NNTP-Posting-Host: p044.euronet.co.uk X-Trace: scavenger.euro.net 1012069728 64723 194.134.224.56 (26 Jan 2002 18:28:48 GMT) X-Complaints-To: abuse@euronet.nl NNTP-Posting-Date: Sat, 26 Jan 2002 18:28:48 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200