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,"Strings have been "
;
Strcat (str1,"concatenated by my Strcat(). "
;
Strcat (str1," Twice !!!"
;
puts (str1);// send new string to console screen
cout << endl;
// the name brand version ----
strcpy (str2,"And this string was "
;
strcat (str2,"concatenated by the original strcat()."
;
strcat (str2," Cool !\n"
;
puts (str2);// send new string to console screen
return 0;
}
#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,"Strings have been "
Strcat (str1,"concatenated by my Strcat(). "
Strcat (str1," Twice !!!"
puts (str1);// send new string to console screen
cout << endl;
// the name brand version ----
strcpy (str2,"And this string was "
strcat (str2,"concatenated by the original strcat()."
strcat (str2," Cool !\n"
puts (str2);// send new string to console screen
return 0;
}