Question

In: Computer Science

Write a function to concatenate two strings using pointer notation

Write a function to concatenate two strings using pointer notation

Solutions

Expert Solution

  • I assume you are C/C++ because of pointer notation.
  • Although I have tested my concatenate function in c,you can use this in c++.
  • I have passed two string pointers in function and the string after concatenation will be pointed by first pointer.
  • Rest I have tried to explain in comments.
  • Below is the whole code in c with a function call in main function.

//Code starts here

#include <stdio.h>
void concatenate_string(char *a, char *b) //Arguments are pointers to strings a and b
{
while(*a) //Loop to move "a" to end of string
a++;

while(*b) //Now we will copy 'b' characters into 'a' until end of b
{
*a = *b;   
a++;
b++;
}
//Note that pointer a will point to concatenated string
*a = '\0'; // '/0' to terminate string
}
int main()
{
char a[100], b[100]; //Defining the two strings

printf("Enter source string\n");
gets(a); //Storing a through user input

printf("Enter string to concatenate\n");
gets(b);
//This function will concatenate a and b and result will be in a
concatenate_string(a, b);
//Printing a
printf("String after concatenation: %s", a);

return 0;
}

//Code ends here


Related Solutions

using python 1. #Write a function called multiply_file_by_index. This function #should take two parameters, both strings....
using python 1. #Write a function called multiply_file_by_index. This function #should take two parameters, both strings. The first string is #the filename of a file to which to write (output_file), and #the second string is the filename of a file from which to read #(input_file). # #In the input file, there will be an integer on every line. #To the output file, you should write the integer from the #original file multiplied by the line number on which it #appeared....
Please write program in c++ with using pointer. create a function that can find the number...
Please write program in c++ with using pointer. create a function that can find the number of even numbers that are between the maximum and minimum elements of an given array.The program have to use pointer. example 8 -1 2 2 1 9 2 4 0 output: 2
Write a Python function that takes two parameters: the first a list of strings and the...
Write a Python function that takes two parameters: the first a list of strings and the second a single string. The function should return True or False depending on whether the string is in the list or not. For example, if the list contains eggs, milk, bananas, and the second parameter is pumpkin, the function should return False. Thank you.
Write a Python function that takes two parameters: the first a list of strings and the...
Write a Python function that takes two parameters: the first a list of strings and the second a single string. The function should return True or False depending on whether the string is in the list or not. For example, if the list contains eggs, milk, bananas, and the second parameter is pumpkin, the function should return False. Thank you.
Exercise 3 – Strings Using a function Write a program that prompts the user to enter...
Exercise 3 – Strings Using a function Write a program that prompts the user to enter two inputs: some text and a word. The program outputs the starting indices of all occurrences of the word in the text. If the word is not found, the program should output “not found”. Example1: Input1: my dog and myself are going to my friend Input2: my Output: 0 11 31 Example 2: Input1: Programming is fun Input 2: my Output: not found
Send an element from 2d array to a function using pointer to pointer. c++ I am...
Send an element from 2d array to a function using pointer to pointer. c++ I am having an issue with being able to send specific elements to the swap function. #include <iostream> using namespace std; void swap(int **a, int **b){    int temp = **a;    **a=**b;    **b=temp; } void selSort(int **arr, int d){    for(int i =0; i<d-1; i++){        int min = *(*arr+i);        int minin = i;        for(int j =i+1; j<d; j++){...
Write a progrm that accepts two strings as input, then indicates if the two strings are...
Write a progrm that accepts two strings as input, then indicates if the two strings are equal when the case of individual letters is ignored. Sample runs are shown below. Use C++ Enter two strings. String 1: PROgraM String 2: proGram PROgraM and proGram are equal. Enter two strings. String 1: litter String 2: LittLe litter and LittLe are not equal.
8.20 Person Pointer Function Make a function that will accept a pointer to a vector of...
8.20 Person Pointer Function Make a function that will accept a pointer to a vector of Person pointers as a parameter. Return a pointer to the Person with the highest salary. The function must be signatured like: Person* getBestPaid(vector*); The class definition is: class Person { public: double salary; string name; }; You may include code in your main() to test, but the tests in this assignment will ensure your code is correct. You may assume there will ways be...
write a function named as cubeCalculator that takes an integer pointer as function and return its...
write a function named as cubeCalculator that takes an integer pointer as function and return its cube value , you are required to compute the cube of a number using pointer notation , return the result as an integer value , use c++
1) Write a function that receives a pointer to an array along with the size of...
1) Write a function that receives a pointer to an array along with the size of the array, it returns the largest number in the array. 2) Write a function that receives a string and returns the length of it.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT