Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please rewrite this C code that concatenates two strings as a function. Do not use strcat /* C program to concatenate two strings without *

Please rewrite this C code that concatenates two strings as a function. Do not use strcat

/* C program to concatenate two strings without * using standard library function strcat() */ #include  int main() { char str1[50], str2[50], i, j; printf(" Enter first string: "); scanf("%s",str1); printf(" Enter second string: "); scanf("%s",str2); /* This loop is to store the length of str1 in i * It just counts the number of characters in str1 * You can also use strlen instead of this. */ for(i=0; str1[i]!='\0'; ++i); /* This loop would concatenate the string str2 at * the end of str1 */ for(j=0; str2[j]!='\0'; ++j, ++i) { str1[i]=str2[j]; } // \0 represents end of string str1[i]='\0'; printf(" Output: %s",str1); return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Readings In Database Systems

Authors: Michael Stonebraker

2nd Edition

0934613656, 9780934613651

More Books

Students also viewed these Databases questions

Question

How do Excel Pivot Tables handle data from non OLAP databases?

Answered: 1 week ago