hi, I want to write a program in C++ that locates strings after acertain command
ID: 3610741 • Letter: H
Question
hi, I want to write a program in C++ that locates strings after acertain command, program takes the input from the command line andlist all the inputs in a linked list using structs.the command is aletter "E" and the following data need to be located after theletter , the data is just a name and an ID number. example : E MIKE 999999 // stored in the linked list . the command line can contain as much as data as thereis, example : E MIKE 999999 E JACK 333333 E DEAN 777777 . . . . . .. the first string after "E" must be a name , and the secondletter is the ID . . . pleas i want the codes with comments . . . hi, I want to write a program in C++ that locates strings after acertain command, program takes the input from the command line andlist all the inputs in a linked list using structs.the command is aletter "E" and the following data need to be located after theletter , the data is just a name and an ID number. example : E MIKE 999999 // stored in the linked list . the command line can contain as much as data as thereis, example : E MIKE 999999 E JACK 333333 E DEAN 777777 . . . . . .. the first string after "E" must be a name , and the secondletter is the ID . . . pleas i want the codes with comments . . .Explanation / Answer
struct student
{
char name[100];
int id;
struct student *next;
}*first,*last;
int insert_node_in_order(struct student *temp)
{
if(first ==NULL)
{
last=first=temp;
}
else
{
last->next = temp;
last =temp;
}
}
int main(int argc,char *argv[])
{
char ch[5];int len;
char name[100];
struct student *temp;
first =NULL;
int count=1;
while(count<argc)
{
temp = new struct student;
strcpy(temp->name,"");
again:
strcat(temp->name,argv[count]);
strcat(temp->name,"");
count++;
if((argv[count][0] >='a'&& argv[count][0]<'z')||(argv[count][0] >='A'&& argv[count][0]<'Z'))
{
goto again;
}
else
temp->id =atoi(argv[count]);
temp->next = NULL;
insert_node_in_order(temp);
count++;
}
temp = first;
while(temp!=NULL)
{
cout<<"Name = "<<temp->name<<endl;
cout<<"Id ="<<temp->id<<endl<<endl;
temp = temp->next;
}
cout<<endl;
system("pause");
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.