当前位置: 技术问答>linux和unix
gcc 下段错误 奇怪的很
来源: 互联网 发布时间:2016-06-26
本文导语: #include #include #include #include #include #define BACKLOG 10 #define LISTENPORT 8888 #define MYPORT 8888 #define _FILE_OFFSET_BITS 64 struct fileifo { char filename[32]; char filepath[32]; long long int filesize; int flag; }; char *filesel; struct fileifo...
#include
#include
#include
#include
#include
#define BACKLOG 10
#define LISTENPORT 8888
#define MYPORT 8888
#define _FILE_OFFSET_BITS 64
struct fileifo
{
char filename[32];
char filepath[32];
long long int filesize;
int flag;
};
char *filesel;
struct fileifo *p=NULL;
void creatdy(int n)/*创建动态数组*/
{
filesel=(char *)malloc(sizeof(char)*n);
p=(struct fileifo *)malloc(sizeof(struct fileifo)*n);
}
void main()
{
int sockfd,new_fd,sin_size= sizeof(struct sockaddr_in),i=0,n;
int flag=0,closeflag=0,filenum=0;
struct sockaddr_in my_addr;
struct sockaddr_in their_addr;
char msg[8704];
char buff[8704];
char filesel[5];
FILE *fp=NULL;
if((sockfd = socket(AF_INET, SOCK_STREAM, 0))==-1)
{
printf("error5");
exit(0); ;
}
their_addr.sin_family = AF_INET;
their_addr.sin_port = htons(MYPORT);
their_addr.sin_addr.s_addr =inet_addr("192.168.0.100"); /*远程IP*/
bzero(&(their_addr.sin_zero),8);
printf("connecting...");
if(connect(sockfd, (struct sockaddr *)&their_addr,sizeof(struct sockaddr))==-1)
{
printf("error6");
exit(0);
}
printf("connect success!n");
recv(sockfd, &filenum, sizeof(int), 0);
creatdy(filenum);
for(i=0;i
#include
#include
#include
#include
#define BACKLOG 10
#define LISTENPORT 8888
#define MYPORT 8888
#define _FILE_OFFSET_BITS 64
struct fileifo
{
char filename[32];
char filepath[32];
long long int filesize;
int flag;
};
char *filesel;
struct fileifo *p=NULL;
void creatdy(int n)/*创建动态数组*/
{
filesel=(char *)malloc(sizeof(char)*n);
p=(struct fileifo *)malloc(sizeof(struct fileifo)*n);
}
void main()
{
int sockfd,new_fd,sin_size= sizeof(struct sockaddr_in),i=0,n;
int flag=0,closeflag=0,filenum=0;
struct sockaddr_in my_addr;
struct sockaddr_in their_addr;
char msg[8704];
char buff[8704];
char filesel[5];
FILE *fp=NULL;
if((sockfd = socket(AF_INET, SOCK_STREAM, 0))==-1)
{
printf("error5");
exit(0); ;
}
their_addr.sin_family = AF_INET;
their_addr.sin_port = htons(MYPORT);
their_addr.sin_addr.s_addr =inet_addr("192.168.0.100"); /*远程IP*/
bzero(&(their_addr.sin_zero),8);
printf("connecting...");
if(connect(sockfd, (struct sockaddr *)&their_addr,sizeof(struct sockaddr))==-1)
{
printf("error6");
exit(0);
}
printf("connect success!n");
recv(sockfd, &filenum, sizeof(int), 0);
creatdy(filenum);
for(i=0;i