if i enter the first command as create
it should print incomplete command...
and then when i again enter create file
as the command it should print Hello
. But it is only printing incomplete command...
but not printing the output Hello
the second time. Please help. I think the global string command is not getting reset every time although i have set it to empty every time the function accept_command
is called. I might be wrong.
enter code here
#include<iostream>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<conio.h>
#include<stdio.h>
using namespace std;
struct node
{
string details;
int shirtnumber;
struct node* next;
};
struct node* head=NULL;
struct node1
{
string details;
int shirtnumber;
struct node1* row;
struct node1* column;
};
struct node1* head1=NULL;
string command="";
string command_words[5]="";
void validate_command()
{
void command_words_calculate();
void accept_command();
command_words_calculate();
if(command_words[1]=="")
{
cout<<"incomplete command...\n"<<endl;
accept_command();
}
if(command_words[0].compare("create")==0)
{
cout<<"Hello\n"<<endl;
accept_command();
}
}
void command_words_calculate()
{
int i,k=0;
char ch,ch1;
string duplicate="";
for(i=0;i<command.length();i++)
{
ch=command.at(i);
if(ch==' ')
continue;
else
break;
}
command=command.substr(i,command.length());
for(i=0;i<command.length();i++)
{
ch=command.at(i);
if(i!=command.length()-1)
ch1=command.at(i+1);
if(ch==' ')
{
if(i!=command.length()-1&&ch1!=' ')
{
k++;
continue;
}
else if(i==command.length()-1)
{
break;
}
else
continue;
}
else
command_words[k]=command_words[k]+ch;
}
}
void display()
{
void accept_command();
cout<<"O.S"<<endl;
accept_command();
}
void accept_command()
{
command="";
void validate_command();
cout<<"root\\:>";
getline(cin,command);
validate_command();
}
int main()
{
void display();
display();
return 0;
}