C programming
1 String Merging
Write a program that reads two strings s1 and s2 from the keyboard and merges them to a string s3. Strings s1 and s2 are statically allocated whereas s3 is dynamically allocated to fit exactly s1 and s2. The two original strings are no longer than 100 characters long. Use the following function to merge the two strings. char *stringMerge(char s1[], char s2 []);
Example:
Enter the first string: Hello world
Enter the first string: This is my first program
Hello worldThis is my first program
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char *stringMerge(char s1[], char s2 []){
int length1 = strlen(s1);
int length2 = strlen(s2);
int i = 0, j = 0, k = 0;
char* result = (char*) malloc(sizeof(char)*(length1+length2+1));
while(i<length1){
result[k++] = s1[i++];
}
while(j<length2){
result[k++] = s2[j++];
}
result[k] = '\0';
return result;
}
int main()
{
char s1[100], s2[100];
char* result;
printf("Enter the first string: ");
scanf("%[^\n]%*c", s1);
printf("Enter the second string: ");
scanf("%[^\n]%*c", s2);
result = stringMerge(s1,s2);
printf("%s",result);
return 0;
}
C programming 1 String Merging Write a program that reads two strings s1 and s2 from...
Write a C program that takes two sets of characters entered by the user and merge them character by character. Enter the first set of characters: dfn h ate Enter the second set of characters: eedtecsl Output: defend the castle Your program should include the following function: void merge(char *s3, char *s1, char *s2); The function expects s3 to point to a string containing a string that combines s1 and s2 letter by letter. The first set might be longer...
You are given a list of strings L = {s1,s2 ...sn}. Each si is a
string of up to 26 English characters. For example, L consists of
the following strings:
{s1, 82... Sn}. Each s; is a string of up to 26 English 13. You are given a list of of strings L = characters. For example L consists of the following strings: S1 =hello', S2 = 'world, s3 = 'what', s4 = 'a', 85 = 'nice', s6 = 'day',...
****Using c++ (Check Substrings) Write the following function to check whether string s1 is a substring of string s2. The function returns the first index in s2 if there is a match. Otherwise, return -1. int indexOf(const string& s1, const string& s2) Write a test program that reads two strings and checks whether the first string is a substring of the second string.
Hello, I need help with my assignment; write a c program that reads a bunch of characters from the keyboard from 'a' through 'z', space, newline and linefeed characters ( using get char), and Keep counts each of the letters 'a' through 'z'.
(Longest common prefix, C-string, loop, char comparison) Write the prefix function to find the longest prefix of two strings using C-strings with the following header: void prefix( const char s1[ ], const char s2[ ], char commonPrefix[ ]) Write a test program that prompts the user to enter two C-strings and displays their common prefix. Sample run :- String 1: Programming is fun String 2: Program logic The common prefix is program.
Write a program that uses String method regionMatches to compare two strings input by the user. The program should prompt the user to enter two strings, the starting index in the first string, the starting index in the second string, and the number of characters to be compared. The program should print whether or not the strings are equal, (Ignore the case of the characters during comparison.) 四SAMPLE RUN #1: java StringCompare Highlight: None D Show Highlighted Only Interactive Session...
Given two C-string s1 and s2, write an if - else if - else statement to print out message to indicate which string goes first in lexicographic order or two strings are the same. It must. Be if-else if -else statement c++
****C PROGRAMMING**** (100 points) Write a program that prompts the user to enter the name of a file. The program encoded sentences in the file and writes the encoded sentences to the output file. Enter the file name: messages.txt Output: encoded words are written to file: messages.txt.swt The program reads the content of the file and encodes a sentence by switching every alphabetical letter (lower case or upper case) with alphabetical position i, with the letter with alphabetical position 25...
Write a recursive method isReverse(String s1, String s2) that takes two strings and returns true if s1 is the reverse of s2, false otherwise. Then, draw the sequence of recursive calls for the following cases. Submit your diagrams in a PDF file called isReverseTrace.pdf. isReverse("happy", "yppah") will return true isReverse("cool", "loac") will return false isReverse("", "") will return true
Write a NASM assembly language(run it on DOSBOX) procedure using string instruction. Given two strings, S1 and S2, determine if S2 is a sub string of S1. Sub string example: S1: ‘I am happy today’, S2: ‘happy’, S2 is a substring of S1. S1: ‘I am happy today’, S2: ‘sad’, S2 is not a substring of S1. Call above procedure in an assembly language program and show the result of the procedure.