Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This assignment focuses on using array structures. Strings are special case of A

ID: 3551018 • Letter: T

Question

This assignment focuses on using array structures. Strings are special case of Arrays


Instructions


Create a program called strings.c that does the following:


Prompt the user and accept a string of no more than 254 characters

Prompt the user and accept a second string of no more than 254 characters

Display the length of both strings (not including the ' ' character)

Create a third string consisting of the first half of string (1) and the second half of string (2).  Display this string

Your program must adhere to the class coding standards, and will be graded using the assignment grading criteria.  Submit your source code file to the Desire2Learn dropbox for this assignment.

video help

Sample Output

Program: String Processing

Author: Doug Jones

Enter string 1: This is a string

Enter string 2: This is also a string


String 1 is 16 characters long, and String 2 is 21 characters long

First half of string 1 and Second half of string 2 is: "This is so a string"

Explanation / Answer

//Because your file name is string.c

//It meeans you have to create a C file instead of C++


#include<stdio.h>

#include<string.h>


int main()

{


char str1[254]; //First string

char str2[254]; //Second string

char strFinal[254]; //Final string

printf("Program : String Processing. Author: Doug Jones ");//Your initial output is here

printf("Enter String 1:");

gets(str1);//To read the input string

printf("Enter String 2:");

gets(str2);//To read the input string

printf("String 1 is %d characters long, and String 2 is %d characters long ",strlen(str1),strlen(str2));//Printing the length using strlen function

printf("First half of string 1 and Second half of string 2 is:");

int i = 0;

int j = 0;

for(i=0;i<strlen(str1)/2;i++)//Copying upto first half of string

{

strFinal[j++]=str1[i];

}

for(i=strlen(str2)/2;i<strlen(str2);i++)//Copying upto later half of second string

{

strFinal[j++]=str2[i];

}

strFinal[j]='';//Making the terminal character.

puts(strFinal);//Printing the final string

return 0;


}