View previous topic :: View next topic |
Author |
Message |
talkerzero Grandmaster Cheater
Reputation: 1
Joined: 24 Jul 2008 Posts: 560 Location: California
|
Posted: Fri Mar 06, 2009 5:27 pm Post subject: [C++ help] Adding a single character to end of string |
|
|
Code: | char* shitfuckedup = "string";
shitfuckedup = shitfuckedup + 's'; |
Why is the value of shitfuckedup simply null? How can I add the 's' to the end of shitfuckedup to make "strings"?
|
|
Back to top |
|
 |
Spawnfestis GO Moderator
Reputation: 0
Joined: 02 Nov 2007 Posts: 1746 Location: Pakistan
|
Posted: Fri Mar 06, 2009 5:38 pm Post subject: Re: [C++ help] Adding a single character to end of string |
|
|
talker0 wrote: | Code: | char* shitfuckedup = "string";
shitfuckedup = shitfuckedup + 's'; |
Why is the value of shitfuckedup simply null? How can I add the 's' to the end of shitfuckedup to make "strings"? |
Code: | char charVariable = "s";
string stringVariable = "lol";
stringVariable += charVariable; |
_________________
CLICK TO HAX MAPLESTORAY ^ !!!! |
|
Back to top |
|
 |
Spudgy Newbie cheater
Reputation: 0
Joined: 13 Jan 2009 Posts: 13
|
Posted: Fri Mar 06, 2009 5:41 pm Post subject: |
|
|
strcat(shitfuckedup,"s");
|
|
Back to top |
|
 |
talkerzero Grandmaster Cheater
Reputation: 1
Joined: 24 Jul 2008 Posts: 560 Location: California
|
Posted: Fri Mar 06, 2009 5:51 pm Post subject: |
|
|
Let me make it a bit more clear.
I want to add a single character, not an array of characters, to the end of an array. For example, I want to add the character 'a' to the end of the array "aaa", not the array "a" to te end of the array "aaa".
Edit: And, I don't wish to use the string identifier.
|
|
Back to top |
|
 |
Spudgy Newbie cheater
Reputation: 0
Joined: 13 Jan 2009 Posts: 13
|
Posted: Fri Mar 06, 2009 5:54 pm Post subject: |
|
|
talker0 wrote: | Let me make it a bit more clear.
I want to add a single character, not an array of characters, to the end of an array. For example, I want to add the character 'a' to the end of the array "aaa", not the array "a" to te end of the array "aaa".
Edit: And, I don't wish to use the string identifier. |
I already told you, just use strcat.
Eg.
Code: |
char* dest = "Hello";
strcat(dest," talker0");
|
|
|
Back to top |
|
 |
talkerzero Grandmaster Cheater
Reputation: 1
Joined: 24 Jul 2008 Posts: 560 Location: California
|
Posted: Fri Mar 06, 2009 6:52 pm Post subject: |
|
|
Added your code to my program. Just closed my window.
Code: | case WM_COMMAND:
if(wParam == IDC_BUTTON1){
char buffer[33];
FilterCharacter("maplestory", 'm', buffer);
MessageBox(hWnd, buffer, "maplestory without the m", MB_OK);
}
break; |
Closed the window when I pressed the button assigned the ID IDC_BUTTON1.
|
|
Back to top |
|
 |
talkerzero Grandmaster Cheater
Reputation: 1
Joined: 24 Jul 2008 Posts: 560 Location: California
|
Posted: Fri Mar 06, 2009 7:41 pm Post subject: |
|
|
Thanks smartz, worked fine.
Just one more thing I'd like to ask: What are __out_z, __in_z, and __in? Can't find them on Google..
Last edited by talkerzero on Fri Mar 06, 2009 7:44 pm; edited 2 times in total |
|
Back to top |
|
 |
smartz993 I post too much
Reputation: 2
Joined: 20 Jun 2006 Posts: 2013 Location: USA
|
Posted: Fri Mar 06, 2009 7:42 pm Post subject: |
|
|
talker0 wrote: | Thanks smartz, worked fine.
Just one more thing I'd like to ask: What are __out_z, __in_z, and __in? Can't find them on Google.. |
__out and __in tell the compiler which way the parameters are coming through..input or output.
The _z tells the compiler that the param is NULL terminated.
**edit:
There is also __in_opt for optional parameters.
|
|
Back to top |
|
 |
talkerzero Grandmaster Cheater
Reputation: 1
Joined: 24 Jul 2008 Posts: 560 Location: California
|
Posted: Fri Mar 06, 2009 7:46 pm Post subject: |
|
|
So if you use void funcName(__out_z int a), you can't read from the variable a inside the function? Am I understanding you correctly?
|
|
Back to top |
|
 |
smartz993 I post too much
Reputation: 2
Joined: 20 Jun 2006 Posts: 2013 Location: USA
|
Posted: Fri Mar 06, 2009 7:51 pm Post subject: |
|
|
talker0 wrote: | So if you use void funcName(__out_z int a), you can't read from the variable a inside the function? Am I understanding you correctly? |
You would only use the _z on a string or character buffer really..
but, using __out, would require a pointer to the variable type.
|
|
Back to top |
|
 |
talkerzero Grandmaster Cheater
Reputation: 1
Joined: 24 Jul 2008 Posts: 560 Location: California
|
Posted: Fri Mar 06, 2009 8:34 pm Post subject: |
|
|
I see.. thanks, smartz, Irwin, everyone.
|
|
Back to top |
|
 |
nog_lorp Grandmaster Cheater
Reputation: 0
Joined: 26 Feb 2006 Posts: 743
|
Posted: Fri Mar 06, 2009 8:47 pm Post subject: |
|
|
Actually, when they are compiled normally, __out and __in and the like are defined to nothing. They are only used for static analysis tools. They also have the nice effect of communicating to the programmer how the variables are used.
_________________
Mutilated lips give a kiss on the wrist of the worm-like tips of tentacles expanding in my mind
I'm fine accepting only fresh brine you can get another drop of this yeah you wish |
|
Back to top |
|
 |
talkerzero Grandmaster Cheater
Reputation: 1
Joined: 24 Jul 2008 Posts: 560 Location: California
|
Posted: Fri Mar 06, 2009 8:53 pm Post subject: |
|
|
@nog_lorp: Wait, then how come in the function posted by Irwin, using _out had a different effect than not using it?
Do you mean to tell me that these two codes will produce the same result?
Code: | void WriteLetterA(__out_z char buffer){
buffer = 'a';
} |
Code: | void WriteLetterA(char buffer){
buffer = 'a';
} |
|
|
Back to top |
|
 |
smartz993 I post too much
Reputation: 2
Joined: 20 Jun 2006 Posts: 2013 Location: USA
|
Posted: Fri Mar 06, 2009 9:34 pm Post subject: |
|
|
talker0 wrote: | @nog_lorp: Wait, then how come in the function posted by Irwin, using _out had a different effect than not using it?
Do you mean to tell me that these two codes will produce the same result?
Code: | void WriteLetterA(__out_z char buffer){
buffer = 'a';
} |
Code: | void WriteLetterA(char buffer){
buffer = 'a';
} |
|
Neither of those will work. You need a pointer to the buffer.
|
|
Back to top |
|
 |
Overload Master Cheater
Reputation: 0
Joined: 08 Feb 2008 Posts: 293
|
Posted: Sat Mar 07, 2009 1:26 am Post subject: |
|
|
talker0 wrote: | Thanks smartz, worked fine.
Just one more thing I'd like to ask: What are __out_z, __in_z, and __in? Can't find them on Google.. |
They are apart of Microsofts standard source code annotation language (SAL language). They provide a set of annotations to describe how a function may use the parameters.
_________________
Blog
Quote: | Rhys says:
you can be my maid
Rhys says:
ill buy you a french maid outfit
Tyler says:
Sounds good
Rhys says:
ill hold you to that |
|
|
Back to top |
|
 |
|