level 3
题目是 要求用mmap编写一个建议的聊天程序。1.c和2.c之间可以相互对话。
马上要交了 什么都不会 麻烦各位大神了!!
2012年09月01日 03点09分
1
level 11
1.c
#include <stdio.h>
int main(void)
{
printf("Hello 2.c\n");
return 0;
}
2.c
#include <stdio.h>
int main(void)
{
printf("Hello 1.c\n");
return 0;
}
2012年09月01日 04点09分
4
pu。。。。我想吐槽了
2012年09月01日 04点09分
代码写的很规范。
2012年09月01日 11点09分
level 13
1.c:
#!/bin/bash
echo "echo hello 2.c" >> 2.c
2.c|1.c &
2.c:
#!/bin/bash
echo "echo hello 1.c" >> 1.c
1.c|2.c &
然后
chmod +x 1.c
chmod +X 2.c
1.c|2.c &
2012年09月01日 04点09分
6
亲 用mmap谢谢。。。
2012年09月01日 04点09分
回复 laiyinan1234 :我只会bash
2012年09月01日 04点09分
level 3
#include <sys/mman.h>#
include
#include <fcntl.h>#
include
#include <stdio.h>#
include #include
typedef struct{ char msg[50]; int flag; //这里我规定1表示1——>2信息,2表示2——>1信息,其他flag表示无效信息}comn;
int main(){ int fd,i; comn *address; char temp[50]; if (fd=open("temp",O_CREAT|O_RDWR|O_TRUNC,022)<0) { perror("file link error!\n"); exit(1); } lseek(fd, sizeof(comn)*5-1, SEEK_SET); write(fd,"",1); address=(comn *)mmap(NULL,sizeof(comn)*5,PROT_READ|PROT_WRITE,MAP_SHARED|MAP_ANONYMOUS,fd,0); close(fd); printf("please input your message\n"); while (1) { for (i=1;i<=5;i++) { if ((*(address+i-1)).flag==1) { printf("端口1:%s",(*(address+i-1)).msg); (*(address+i-1)).flag=3; } } scanf("%s",temp); for (i=1;i<=5;i++) { if ((*(address+i-1)).flag==3) { memcpy((*(address+i-1)).msg,&temp,50); (*(address+i-1)).flag=2; } } } munmap(address,sizeof(comn)*5); return 0;}
2012年09月01日 05点09分
9
排版,要么贴链接
2012年09月01日 05点09分
回复 reverland :稍等一下
2012年09月01日 06点09分
level 3
#include <sys/mman.h>#
include
#include <fcntl.h>#
include
#include <stdio.h>#
include #include
typedef struct{ char msg[50]; int flag; //这里我规定1表示1——>2信息,2表示2——>1信息,其他flag表示无效信息}comn;
int main(){ int fd,i; comn *address; char temp[50]; if (fd=open("temp",O_CREAT|O_RDWR|O_TRUNC,00777)<0) { perror("file link error!\n"); exit(1); } lseek(fd, sizeof(comn)*5-1, SEEK_SET); write(fd,"",1); address=(comn *)mmap(NULL,sizeof(comn)*5,PROT_READ|PROT_WRITE,MAP_SHARED|MAP_ANONYMOUS,fd,0); close(fd); printf("please input your message\n"); for (i=1;i<=5;i++) { (*(address+i-1)).flag = 3; } while (1) { for (i=1;i<=5;i++) { if ((*(address+i-1)).flag == 1) { printf("端口1:%s\n",(*(address+i-1)).msg); (*(address+i-1)).flag=3; } } scanf("%s",temp); for (i=1;i<=5;i++) { if ((*(address+i-1)).flag == 3 ) { memcpy((*(address+i-1)).msg,&temp,50); (*(address+i-1)).flag=2; } } } munmap(address,sizeof(comn)*5); return 0;}
2012年09月01日 06点09分
10
怎么还是这样的。。。
2012年09月01日 06点09分
level 8
楼主这种伸手党真是悲剧
连作业毕业设计都要伸手的
到了社会简直一无是处
2012年09月01日 07点09分
13
你塔码算什么狗 谁告诉你是什么毕业作业了 这么难度的毕业作业只有配你这种杂种 滚出我视线
2012年09月01日 08点09分
回复 laiyinan1234 :呵呵!笑而不语……
2012年09月01日 08点09分
无论怎么说伸手党是不对的
2012年09月01日 09点09分
回复 叠搭宝箱 :网络上多的是这种弄不清楚就胡乱说的人,好像自己高高在上,充满官僚之风,自大之气,我最不屑了。刚才爆了爆粗口,他应得的。 程序我已经自己写好了
2012年09月01日 10点09分
level 8
mmap这种还要请人送代码 这个我不知道该怎么说……
2012年09月03日 01点09分
16