Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rewrite of srcat()/

Status
Not open for further replies.

johndw

Technical User
Nov 15, 2001
8
0
0
US
I wrote this little program that mimics strcat() - it works ok. But now I need to rewrite it to use pointers instead of passing (by reference)or indexing. Can you guys help with this one ?
#include
#include //for console i/o
#include //for getch()
#include //for string manipulation

int const SIZE = 40;//for good measure

/* -- taken from the help files of Microsoft...----------------
* Append a string. *
* *
* char *strcat( char *strDestination, const char *strSource );*
*------------------------------------------------------------*/

//---------- here we go ---
void Strcat(char s1[40],char s2[40])
{
int i=0,j=0,x,len1,len2;

len1 = strlen(s1);
len2 = strlen(s2);

x = len1;
/* Adding to string1 from null character with string2 (s1[x])
x is the length of string1 which is the point of the string's
null character. */

for(i = 0;i <= len2;i++){//looping through the strings...
s1[x] = s2;
x++;
}
}
//-------------
int main ()
{
char str1[80];// a string goes in here
char str2[80];// another will go here

// aftermarket version ----
strcpy (str1,&quot;Strings have been &quot;);
Strcat (str1,&quot;concatenated by my Strcat(). &quot;);
Strcat (str1,&quot; Twice !!!&quot;);
puts (str1);// send new string to console screen
cout << endl;

// the name brand version ----
strcpy (str2,&quot;And this string was &quot;);
strcat (str2,&quot;concatenated by the original strcat().&quot;);
strcat (str2,&quot; Cool !\n&quot;);
puts (str2);// send new string to console screen

return 0;
}
 
I think I figured out on my own. But if anyone wants to try this, I'd enjoy seeing what comes of it.
-john
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top