Q3 having a string of name conta pointers to construct three new
![* Q3 having a string of name contains first, second and last name use
pointers to construct three new strings to save each name.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F88cb5de0-1d27-4f3b-970a-d2666eec9af2%2F256d493b-a1ce-432e-9f77-49bd53805757%2F3z4sq1_processed.jpeg&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
/*Program to gets first, second and last name from name string*/
#include <stdio.h>
//main function of program
int main()
{
//variables for name. first, second and last name
char name[100] = "Mary Elizabeth Smith";
char fname[50] = "\0";
char sname[50]= "\0";
char lname[50]= "\0";
//pointer variable
char * ptr = name;
int count =0;
int i,j,k,l;
j=k=l=0;
//loop through each character in name and collect first,second and last name
for(i=0; i<strlen(ptr); i++){
if(ptr[i] == ' ')
{
count++;
}
if(count ==0)
{
fname[j++] = ptr[i];
}
if(count ==1)
{
sname[k++] = ptr[i];
}
if(count ==2)
{
lname[l++] = ptr[i];
}
}
//display first, second and last name
printf("\n fname : %s", fname);
printf("\n sname : %s", sname);
printf("\n lname : %s", lname);
return 0;
}
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)