Question: #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; struct userlogin { string username,password; }; bool Login(string username,string password);

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

using namespace std;

struct userlogin

{

string username,password;

};

bool Login(string username,string password);

void SignUp(string username,string password);

void write1(void *ptr);

void read1(void *ptr);

string chatread(string username,string message,string time);

int main()

{

userlogin *obj =new userlogin[2];

int user,choice,count=0;

system("clear");

cout<<"1. Single user ChatRoom ";

cout<<"2 .Group ChatRoom ";

cout<<"3. Exit ";

cout<<"\t\t";

cin>>user;

if(user==1)

{

do

{

system("clear");

cout<<"\t\t Single User ChatRoom ";

cout<<"\t\t Enter user credentials ";

cout<<" \t\t SignIn \t\t Signup ";

cout<<"\t\t";

cin>>choice;

if(choice==1)

{

system("clear");

cout<<"\t\t Username :";

cin>>obj[count].username;

cout<<"\t\t Password :";

cin>>obj[count].password;

if(Login(obj[count].username,obj[count].password))

{

cout<<" \t\t login Sucessfully ";

count++;

if(count==2)

{

mkfifo("fifo",0777);

thread t1(write1,obj);

thread t2(read1,obj);

t1.join();

t2.join();

}

sleep(3);

system("clear");

continue;

}

}

else if(choice==2)

{

cout<<"\t\tUsername : ";

cin>>obj[count].username;

cout<<"\t\tPassword: ";

cin>>obj[count].password;

if(Login(obj[count].username,obj[count].password))

{

cout<<" \t\t Please choose other username ";

sleep(3);

}

else

{

SignUp(obj[count].username,obj[count].password);

cout<<" \t You have sucessfully Signup!!";

sleep(2);

}

system("clear");

}

} while(true);

}

return 0;

}

string readchat(string username)

{

string chat="",readchat="";

ifstream inputFile;

inputFile.open(username+"File.txt",ios::in);

while (getline(inputFile,readchat))

{

chat +=readchat+" ";

}

inputFile.close();

return chat;

}

void writechat(string username,string message,string time)

{

ofstream outputFile;

outputFile.open(username+"File.txt",ios::app);

outputFile<

outputFile.close();

}

void write1(void *ptr)

{

struct userlogin *myData=(struct userlogin *)ptr;

int res;

time_t t=time(NULL);

struct tm*tm=localtime(&t);

char arr1[200],arr2[200];

string time=" ";

myData[1].username,fileUsername2=myData[1].username+myData[0].username;

while (1)

{

time=asctime(tm);

cout<<" Write your text: ";

res=open("fifo",O_WRONLY);

fgets(arr1,200,stdin);

write(res,arr1,strlen(arr1)+1);

writechat(myData[0].username,arr1,time);

writechat(myData[0].username+myData[1].username,arr1,time);

writechat(myData[1].username+myData[0].username,arr1,time);

sleep(3);

close(res);

res=open("fifo",O_RDONLY);

read(res,arr2,sizeof(arr2));

cout<

close(res);

}

}

void read1(void *ptr)

{

struct userlogin * myData=(struct userlogin*)ptr;

int res_2;

time_t t=time(NULL);

struct tm*tm=localtime(&t);

string time="";

char arr1[200],arr2[200];

while (1)

{

time=asctime(tm);

res_2=open("fifo",O_RDONLY);

read(res_2,arr2,200);

cout<

close(res_2);

cout<<" Write a message : ";

res_2=open("fifo",O_WRONLY);

fgets(arr1,200,stdin);

write(res_2,arr1,strlen(arr1)+1);

close(res_2);

}

}

void Signup(string username,string password)

{

ofstream outputFile;

outputFile.open("loginFile.txt",ios::app);

if(!outputFile)

{

cout<<"File not found ";

}

outputFile<

outputFile.close();

}

bool Login(string username,string password)

{

string fusername,fpassword;

ifstream inputFile;

inputFile.open("loginFile.txt");

if(!inputFile)

{

cout<<"Username or password not found!!! ";

}

else

{

while(inputFile>>fusername)

{

inputFile>>fpassword;

if((fusername==username) &&(fpassword==password))

{

return true;

}

}

}

inputFile.close();

return false;

}

FIX THE CODE AND RUN IT ON UBUNTU

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!