|
#include"stdio.h"
#include"string.h"
#include"stdlib.h"
#include"time.h"
#define MAX_PKT 1024
#define MAX_SEQ 7
typedef enum {FALSE, TRUE} boolean;
typedef unsigned int seq_nr;
typedef enum {dat, ack, nak} frame_kind;
typedef enum event_type {timeout, frame_arrival};
typedef struct
{ frame_kind kind;
seq_nr seq;
seq_nr ack;
char info[1024];
} frame;
void from_network_layer(frame *fra)
{
printf("输入信息:");
memset(fra->info, 0, strlen(fra->info));
for(int i = 0; ; i++)
{
fra->info[i] = getchar();
if ('\n' == fra->info[i])
{
fra->info[++i] = '\0';
break;
}
}
}
void to_physical_layer(frame *fra)
{
FILE *fp1;
char buf[1024];
char temp;
memset(buf, 0 ,strlen(buf));
switch(fra->kind)
{
case dat:
strcpy(buf, "dat");
break;
case ack:
strcpy(buf, "ack");
break;
case nak:
strcpy(buf, "nak");
break;
}
itoa(fra->ack, &temp, 10);
strcat(buf, &temp);
itoa(fra->seq, &temp, 10);
strcat(buf, &temp);
strcat(buf, fra->info);
// strcat(buf, '/0');
if(0 == (fp1= fopen("d:\\a.txt","r")))
{
printf("文件创建失败");
fclose(fp1);
}
else
{
fwrite(buf, 1, 1024, fp1);
fclose(fp1);
}
printf("success");
}
event_type wait_for_event()
{
return frame_arrival;
}
void main()
{
seq_nr ack = 0;
frame send, rev;
event_type event;
from_network_layer(&send);
send.kind = dat;
send.ack = 0;
send.seq = 0;
to_physical_layer(&send);
event = wait_for_event();
}
一调试到WAIT_FOR_EVENT()RETURN就显示UNHANDLED EXCEPTION,如果把TO_PHYSICAL_LAY()屏蔽就能正常返回,高手来指点下,小弟先谢谢了! |
|