string input and output, and manipulating strings using the string.h library. In
ID: 3630884 • Letter: S
Question
string input and output, and manipulating strings using the string.h library.
Instructions
Create a program called stringProcessing.c that does the following:
1. Prompt the user and accept a string of no more than 254 characters
2. Prompt the user and accept a second string of no more than 254 characters
3. Display the length of both strings (not including the ' ' character)
4. Create a third string consisting of the first half of string (1) and the second half of string (2). Display this string
Explanation / Answer
#include<stdlib.h>
#include<string.h>
main(){
char string1[254];
char string2[254];
printf("enter a string of less than 254 characters ");
scanf("%s",string1);
printf("enter another string of less than 254 characters ");
scanf("%s",string2); int length1=strlen(string1);
int length2=strlen(string2);
printf("length of string 1 is %d",length1); printf("length of string 2 is %d",length2);
char string3[254];
strncpy(string3,string1,length1/2);
int j=0;int i=0; char string4[254];
for(i=length2;i>-1;i--){
strcat(&string4[j],&string3[i]);
j++;}
strncat(string3,string4,length2/2); printf(" %s",string3); }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.