Article View: alt.comp.lang.learn.c-c++
Article #305pass structure by reference / by value
From: EL
Date: Sat, 26 Jan 2002 16:46
Date: Sat, 26 Jan 2002 16:46
46 lines
1887 bytes
1887 bytes
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:
<a2um2g$1q1@imsp212.netvigator.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!newsgate.cuhk.edu.hk!newsgate.netvigator.com!imsp212.netvigator.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f8d38,d119aab9300bf461,start X-Google-Attributes: gidf8d38,public X-Google-Thread: 114592,d119aab9300bf461,start X-Google-Attributes: gid114592,public X-Google-Thread: 109fba,d119aab9300bf461,start X-Google-Attributes: gid109fba,public X-Google-ArrivalTime: 2002-01-26 08:42:03 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!newsgate.cuhk.edu.hk!newsgate.netvigator.com!imsp212.netvigator.com!not-for-mail From: "EL" <lameddie@yahoo.com> Newsgroups: alt.comp.lang.learn.c-c++,borland.public.cpp.language,comp.lang.c++ Subject: pass structure by reference / by value Date: Sun, 27 Jan 2002 00:46:30 +0800 Organization: IMS Netvigator Lines: 48 Message-ID: <a2um2g$1q1@imsp212.netvigator.com> NNTP-Posting-Host: pcd272200.netvigator.com X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000