Write code to split an input string (variable \"name\") into twooutput strings (
ID: 3613928 • Letter: W
Question
Write code to split an input string (variable "name") into twooutput strings (variables "first" and "last"). Assume that the userprovides input containing only the characters a through z and Athrough Z. Assume that there are exactly two capital letters in theinput, one at beginning of the first name, and one at the beginningof the last name. For example, given input "JoeSmith" , your codeshould split it iinto "Joe" and "Smith". Your code should use thefollowing line: char name[50], last[50]; printf(" What your name? "); scanf("%s", name); Write code to split an input string (variable "name") into twooutput strings (variables "first" and "last"). Assume that the userprovides input containing only the characters a through z and Athrough Z. Assume that there are exactly two capital letters in theinput, one at beginning of the first name, and one at the beginningof the last name. For example, given input "JoeSmith" , your codeshould split it iinto "Joe" and "Smith". Your code should use thefollowing line: char name[50], last[50]; printf(" What your name? "); scanf("%s", name);Explanation / Answer
please rate - thanks #include<stdio.h>#include <string.h>
#include <conio.h>
int main()
{int i=1,j=0;
char name[50],last[50];
printf("What is your name? ");
scanf("%s",name);
while(name[i]>='a'&&name[i]<='z')
i++;
last[j]=name[i];
name[i]='';
i++;
j++;
while(name[i]!='')
{last[j]=name[i];
j++;
i++;
}
last[j]='';
printf("first name: %s last name:%s ",name,last);
printf(" ");
getch();
return 0;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.