1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
#include<fstream.h>
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<dos.h>
void main()
{
clrscr();
fstream F;
char name[15], chat[100], room[12];
int ch, post=0, n=0, hut=0;
cout<<"Enter ur screen name: "; cin>>name;
cout<<"Enter Room Name: "; cin>>room;
changeroom:
strcat(room,".txt");
F.open(room,ios::app);
F<<endl<<endl<<"*** "<<name<<" has just joined the chat ***"<<endl;
F.close();
while(1)
{
delay(60);
hut++;
clrscr();
char STR[102];
//CHAT DISPLAY
F.open(room,ios::in);
while(!F.eof())
{
F.getline(STR,102);
cout<<STR<<endl;
}
F.close();
//USER INPUT
char colon[102]=": ", whencename[117];
strcpy(whencename,name);
cout<<"--------------------------------------------------------------------------------"<<endl<<name<<colon<<chat;
if(kbhit())
{
ch=getch();
if((ch!=8)&&(ch!=13)){ chat[n++]=ch; chat[n]='\0';}
else if(ch==13) post=1;
else if (n>0) chat[--n]='\0';
else chat[0]='\0';
}
if(post)
{
post--;
if(strcmpi("/truncate",chat)==0)
{
ofstream Fdelete(room);
Fdelete.close();
}
else if(strcmpi("/name",chat)==0)
{
cout<<"\n\n\tEnter New Name: "; cin>>name;
}
else if(strcmpi("/room",chat)==0)
{
cout<<"\n\n\tEnter New Room: ";cin>>room;
n=0; chat[0]='\0';
goto changeroom;
}
else
{
strcat(colon,chat);
strcat(whencename,colon);
F.open(room,ios::app);
F<<endl<<whencename;
F.close();
}
n=0; chat[0]='\0';
}
}
getch();
}
|