By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,851 Members | 2,097 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,851 IT Pros & Developers. It's quick & easy.

One question only ---ANSI C

P: 27
Please help me . I am new at C , Learing C will take time but i have to submit this and i dont know how to do it honestly so please help anyone .
thanks in advance .I will understand each line of code so as to understand ANSI C well.
______________________________________________

Write a function with the following prototype

Char *mystrcat(char *s, char *p);

The function appends string p to the end of string s and returns a pointer to the start of string s.
Remember that strings are terminated by binary zero (‘\0’).

Suppose string s contains “abcd” and string p contains “xyz”. The result would be string s containing “abcdxyz”.

Use the program section below to test your program:
#include <ctype.h>

char *mystrcat(char *s,char *p);

main()
{
Char string1[80], string2[80];
For ( ; ; )
{
Printf(“Enter string1: “);
Scanf(“%s”, &string1);
If (!strcmp(string1, “done”))
Break;
Printf(“Enter string2: “);
Scanf(“%s”, &string2);
Printf(“String1: %s String2: %s\n”, string1, string2);
Printf(“Returned string : %s\n”, mystrcat(string1,
string2);
Printf(“String1: %s String2: %s\n”, string1, string2);
}
}

Hint : ctestchar = *(ptrstring++) – assigns the character pointer to by ptrstring to the character ctestchar and moves the pointer on by one character

--------------------------------------------------------------------------------
Nov 5 '06 #1
Share this Question
Share on Google+
1 Reply


P: 4
Write a function with the following prototype

Char *mystrcat(char *s, char *p);

The function appends string p to the end of string s and returns a pointer to the start of string s.
Remember that strings are terminated by binary zero (‘\0’).

Hi there,
Here is a small code snippet that concatenates two strings. See if this works for you.
char *myCat(char *string1,char*string2)
{
char *tempBuf,*ret;
m=(char*)calloc(1,strlen(string1)+strlen(strling2) +1);
ret=tempBuf;
while(*string1!='\0')
{
*tmpBuff++=*string1++;
}
while(*string2!='\0')
{
*tmpBuff++=*string2++;
}
*tmpBuf='\0';
return ret;

}

Hope this helps you.
Aarthy.
Nov 5 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.