Forum Replies Created
- AuthorPosts
- arun_raj7Participant
You can use any of c functions in c++ or mfc as long as you include the correct headers.
Also I believe the correct syntax for that would be itoa(VartoShow,&ChatToConvert,10);
You use the ampersand character to point to the string, you cant automatically put a string into a function parameter in accordance to how c++ conducts itself.arun_raj7Participant@ahsun
Unless you are saving the source to the include directory and compiling from thereof, you need the brackets “<" & ">” around the include headers, not just quotes. Also, I am pretty sure he wasnt looking for a program to print two strings to output, Im pretty sure he was looking to get the string the user wanted to “swap” and then “swap” it.
@chaitanya.b
Im not sure quite how you mean. A program would have to use some major heuristics to be able to decipher something of that sort. Maybe you are talking about something that would do something like this:
“hello im a string”
“string a im hello”If that is so then you can use strtok() to truncate the string to whitespace then print them in reverse order. If you wish to not use the library functions to reverse the string itself, you can write a strtok() function yourself and use it that way. Mainly, you would have to use homebrew functions to do the work for you, lets see if i can dig up some source code I may have laying around somewhere…
Ok here are some examples of the functions, I dont remember who wrote them but I guess they work… I have never used them so dont expect anything great…
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849#define NULL ' ';<br />// my strcmp() function<br />int mCmp(char *f, char *s)<br />{<br />if (f==s)<br />return 0;<br />return 1;<br />}<br />// my string length<br />int mslen(char *ch)<br />{<br />char[] bf = ch;<br />int y=0;<br />do{<br />y++;<br />}while (bf[y]!=NULL);<br />return y;<br />}<br />//my strtok() example<br />char* mstrtok(char *first, const char *sec)<br />{<br />char[] buff; //first buffer<br />char[] buf; //second buffer<br />buff = first; // initialize first buffer<br />buf[0]=buff[0]; // initialize second<br />for (int x=0;x<mslen(buff);x++)<br />{<br />if (mCmp(buff[x],(char *)sec)<br />return &buf; // if our next character equals the control character we will end and return buf<br />buf[x]=buff[x];//copy next bit<br />}<br />//if this point should be reached then return the string<br />return &buf;<br />}<br />// my concat example - strcat()<br />char* mconcat(char *fir, char *sec)<br />{<br />int y=0;<br />for (int x = 0;x<mslen(fir);x++)<br />{<br />if (fir[x]==NULL)<br />{<br />x--;<br />for (y=0;y<mslen(sec);y++)<br />x++;fir[x] = sec[y];<br />return fir;<br />}<br />}<br />} - AuthorPosts