Question

Concatenation of two strings using pointers Step 1: Ask the user to input ni,n2 and create two character arrays (strings) wit
Please help me to make this c programming code!! Thank you!!
0 0
Add a comment Improve this question Transcribed image text
Answer #1

The code in c is given below.

#include<stdio.h>
int main()
{
   int n1,n2;
   printf("Please enter the value of n1 and n2: ");
   scanf("%d%d",&n1,&n2);/*user input sizes*/
   char *str1;
   char *str2;
   str1=(char*)malloc(sizeof(char)*n1);
   str2=(char*)malloc(n2*sizeof(char));
   printf("Please Enter string1: ");
   scanf("%s",str1);
   printf("Please Enter string2: ");
   scanf("%s",str2);
   char *str3;
   str3=(char*)malloc(sizeof(char)*(n1+n2));
   int i;
   for(i=0;i<n1;i++)
   {
   *(str3+i)=*(str1+i); /*copying the first string*/
   }
   for(i=0;i<n2;i++)
   {
   *(str3+i+n1)=*(str2+i); /*adding second string*/
   }
   for(i=0;i<n1+n2;i++)
   {
   printf("%c",*(str3+i)); /*printing the resultant string*/
   }
   return 0;  
}



The screenshot of the running code and output is given below.

1 2 8 10 #include<stdio.h> int main() 3 { 4 int n1, n2; 5 printf(Please enter the value of nl and n2: ); scanf(%d%d,&n1,&

Please enter the value of n1 and n2: 3 2 Please Enter string1: ABC EF Please Enter string2: ABCEF Process exited after 13.94






If the answer helped please upvote it means a lot. For any query please comment.

Add a comment
Know the answer?
Add Answer to:
Please help me to make this c programming code!! Thank you!! Concatenation of two strings using...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • using c and pointers only 1. You will read in two strings from a file cp4in_1.txt...

    using c and pointers only 1. You will read in two strings from a file cp4in_1.txt at a time (there will be 2n strings, and you will read them until EOF) and then do the following. You alternately take characters from the two strings and string them together and create a new string which you will store in a new string variable. You may assume that each string is no more than 20 characters long (not including the null terminator),...

  • Help please this is C/C++ code /* * Lab12, the purpose of this lab is to...

    Help please this is C/C++ code /* * Lab12, the purpose of this lab is to improve your skills in handling c strings * with pointers . * use of : strlen ,string concatenation strcat, compare strcmp, * copy strcpy and search strrchr * */ #include <cstdlib> #include <iostream> #include<cstring> using namespace std; /** * Create a method that prompts the user for only lowercase letters to represent * a name. * Start a Label, then prompt the user to...

  • I need help please... Intro to Programming in C – small program 8 Project objective: To...

    I need help please... Intro to Programming in C – small program 8 Project objective: To compile, build, and execute an interactive program using character arrays and string.h functions **Submit source code (prog8.c) through Canvas • One source code file (unformatted text) will be submitted • The file name must match the assignment • The code should be tested and run on a Microsoft compiler before it is uploaded onto Canvas • The code must be submitted on time in...

  • Please help code in c++ and use the answers you get from question 1 and 2...

    Please help code in c++ and use the answers you get from question 1 and 2 into the 3rd answer! Question 1 is first, question 2 is in the middle, question 3 is last Input Array (10 pts) te a function only (no main) that takes an array of doubles as a parameter as well as another integer rray. Create a for loop that asks the user to input any real number between-100 and r each element of the array....

  • I'm using code blocks to perform this. These problems are from my C Programming Beginners book....

    I'm using code blocks to perform this. These problems are from my C Programming Beginners book. Not too familiar with C programming so any help would be great. I would like to see how it is formatted. Also, I don't understand Problem 4 at all. Thanks. 1- Create three integer variables and initialize to zero. 2- Create three float variables and initialize to zero. 3- Create three double variables and initialize to zero. 4- Create one character variables and initialize...

  • using c only You will read in two strings from a file cp4in_1.txt at a time...

    using c only You will read in two strings from a file cp4in_1.txt at a time (there will be 2n strings, and you will read them until EOF) and then do the following. You alternately take characters from the two strings and string them together and create a new string which you will store in a new string variable. You may assume that each string is no more than 20 characters long (not including the null terminator), but can be...

  • Need help writing this lab. Directions in lab attachment above. Thank you. Output should look like...

    Need help writing this lab. Directions in lab attachment above. Thank you. Output should look like ones in attachment ab Ass Part 1 sing Static Arra Do this part on your own. Write a program named lab11 a.c containing the following function: preconditions arc is terminated by dest is big enough hold arc postconditions dest contains src and is terminated by "10" void my strcpy (char dest const char srclj) This function will take two character arrays as parameters. The...

  • This must be a C PROGRAMMING script using ARRAY. Thank you :) 3. Create a script...

    This must be a C PROGRAMMING script using ARRAY. Thank you :) 3. Create a script that will take an array of numbers and show the numbers in reversed order. Size of Array and elements have to be prompted to the user. Another Array variable of the same type should keep the numbers in reversed order. a. b. EX) If A 11, 2, 3,4, 5) was chosen as input, the output 8 should be B-(5, 4, 3,2, 1

  • In C Programming Language In this lab you will implement 4 string functions, two using array...

    In C Programming Language In this lab you will implement 4 string functions, two using array notation and two using pointers. The functions must have the signatures given below. You may not use any C library string functions. The functions are 1. int my strlen (char s ) - This function returns the number of characters in a string. You should use array notation for this function. 2. int my strcpy (char s [], char t I)- This function overwrites...

  • C++ Programming help, please include comments to help me understand the code. Thank you for helping....

    C++ Programming help, please include comments to help me understand the code. Thank you for helping. Task C: Substitution and Hamming Distance For this task, we will explore mutations that occur by substitution. Your task is to write a program called hamming.cpp that calculates the Hamming distance between two strings. Given two strings of equal length, the Hamming distance is the number of positions at which the two strings differ. e. g.: Hamming("aactgc", "atcaga") would output 3. Notice that certain...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT