Joining Two Strings coderinme

Joining Two Strings coderinme

Joining Two Strings coderinme
Concatenate means to join two strings which means to paste the latter string just at the end of former string. We can do this using different options. But here we will use the concept of Pointer. So let us write a program that will concatenate one string to the end of other string and display it as output without using pre-defined function.

#include<stdio.h>
void str_cat(char * p, char * q) {
while( *p != '\0' ) {
p++;
}
while (*q != '\0')
{
*p = *q;
p++;
q++;
}
*p = '\0';
}
int main()
{
char a[100],b[100];
printf("\nEnter the First String: ");
gets(a);
printf("Enter the Second String: ");
gets(b);
str_cat(a,b);
printf("\nString After concatenation:\n%s",a);
getch();
return 0;
}

For more programs in C, visit our C Coder Archives

Joining Two Strings coderinme

All rights reserved. No part of this Post may be copied, distributed, or transmitted in any form or by any means, without the prior written permission of the website admin, except in the case of brief quotations embodied in critical reviews and certain other noncommercial uses permitted by copyright law. For permission requests, write to the owner, addressed “Attention: Permissions Coordinator,” to the admin @coderinme

Leave a reply:

Your email address will not be published.