C++如何做网络聊天工具?
C++如何做网络聊天工具?求源码(我只要DOS窗口的即可)发到:o7007@vip.qq.com
答案:#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <sys/types.h> /* See NOTES */
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <errno.h>#ifndef LINKLIST_H
#define LINKLIST_H#define N 64
typedef struct
{
int type;
char name[16];
char text[N];
} mesg;typedef struct sockaddr_in datatype;
typedef struct _node_
{
datatype cliaddr;
struct _node_ *next;
} linknode, *linklist;int cmp(datatype x, datatype y) {
if(x.sin_family == y.sin_family
&& x.sin_port == y.sin_port
&& x.sin_addr.s_addr == y.sin_addr.s_addr)
return 1;
return 0;
}linklist CreateEmptyLinklist()
{
linklist h;h = (linklist)malloc(sizeof(linknode));
h->next = NULL;return h;
}void InsertLinklist(linklist h, datatype x)
{
linklist p = h, q;q = (linklist)malloc(sizeof(linknode));
q->cliaddr = x;while (p->next != NULL)
p = p->next;
q->next = p->next;
p->next = q;return;
}void DeleteLinklist(linklist h, datatype x)
{
linklist q = h->next;while (NULL != q)
{
if (cmp(q->cliaddr, x))
{
h->next = q->next;
free(q);
}
else
{
h = q;
}
q = h->next;
}return;
}void ClearLinklist(linklist h)
{
linklist p = h->next, q;while (p != NULL)
{
q = p;
p = p->next;
free(q);
}h->next = NULL;
return;
}#endif
这个文件命名为linklist.h
上一个:C++小程序出错(结构体)
下一个:关于斐波那契数列的C++课程设计