Thursday, February 12, 2009

Chatting Application in C++

Here it is basic chatting application in c/c++ that will give you idea about serial communication in c/c++


#include
#include
#include
void send()
{
char c[100];
int port=0x3f8,i;
printf("\nEnter String u want to send: ");
flushall();
gets(c);
for(i=0;c[i];i++)
{
outpw(port,c[i]);
}
c[i+1]='*';
outpw(port, c[i+1]);
printf("String is sent.");
getch();
}

void recieve()
{
int port=0x3f8,i=-1;
char c[100];
clrscr();
getch();
do{
i++;
c[i]=inpw(port);
if(c[i]=='*')
c[i]=NULL;

}while(c[i]);
puts(c);
getch();
}

void main()
{
int ch;
clrscr();
do{
printf("\n1.Send\n2.Receive\n3.Exit\n\n\tEnter your choice: ");
scanf("%d",&ch);
switch(ch){
case 1: send();
break;
case 2: recieve();
break;
case 3: break;
default: printf("Wrong choice!!");
break;
}
}while(ch!=3);
}

No comments:

Post a Comment