Ive tried making my own strcat function but i need help in returning the array or whole string in the my_strcat function.
How do i return that array?
Im trying strcat with array notation, but kidna stuck.
cheers
Code:
#include <stdio.h>
#include <strings.h>
#define SIZE 1000
void get_words( char [] );
char *my_strcat( char [], char [] );
int main()
{
char words[SIZE];
char words2[SIZE];
printf( "Enter String1:\n" );
get_words( words );
printf( "Enter String2:\n" );
get_words( words2 );
/* printf( "Enter String 2:\n" );
get_words2( words2 );
*/
printf( "string1: %s", words );
printf( "\n" );
printf( "string2: %s", words2 );
printf( "\n" );
printf( "concat: %s", my_strcat( words, words2 ) );
return 0;
}
void get_words( char string[] )
{
int ch;
int n=0;
while( (ch=getchar()) != '\n' ) {
string[n] = ch;
n++;
}
}
char *my_strcat( char words1[], char words2[] )
{
int n=0;
int i=0;
char temp[SIZE];
/* copy words1 into temp without the null byte */
while( words1[i] != '\0' ) {
temp[n] = words1[i];
n++;
i++;
}
i=0; /* reset i to zero */
/* insert a blank space after the word being copied */
temp[n] = ' ';
/* copy words2 in temp after the blank space */
while ( words2[i] != '\0' ) {
temp[n] = words2[i];
i++;
}
/* insert a null byte at end of temp for complete string */
temp[n] = '\0';
return temp;
}