Mail Archives: djgpp/1998/03/24/18:15:36
From: | James W Sager Iii <sager+@andrew.cmu.edu>
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Re:?Functions recieving strings?
|
Date: | Mon, 23 Mar 1998 23:27:14 -0500
|
Organization: | Junior, MCS Undeclared, Carnegie Mellon, Pittsburgh, PA
|
Lines: | 49
|
Message-ID: | <Ip5nMWq00WB815Vks0@andrew.cmu.edu>
|
NNTP-Posting-Host: | andrew.cmu.edu
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
I feel kinda stupid answering my own question, but
the problem I found is the following:
void wierd(char *s1)
{
strcat(s1,"_PCX");
cout<<s1<<endl;
}
void main(void)
{
wierd("1");
wierd("2");
}
The output is:
1_PCX
PCX_PCX
appearantly, if you go past the terminating character on char*'s
you pass to functions, they accept whatever is past the one character
as the input for the function the next time.
Hense
'_' is the first character
'PCX' is the next three.
I guess to manipulate strings one should first copy them to a new string.
Which is:
void wierd(char *s1)
{
char *s2;
strcpy(s2,s1)
strcat(s2,"_PCX");
cout<<s2<<endl;
}
Again. I feel stupid for answering my own question...
I'm sure most of you knew this, but I worded my question badly so I
figured it would be a good idea to explain what my problem was.
Thanks all who tried to help even though my question couldn't have been
more vague, and my example any worse :P
- Raw text -