|
#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 ("Input information:");
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 ("File creation failed");
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 ();
}
As soon as you debug to WAIT_FOR_EVENT () RETURN, UNHANDLED EXCEPTION is displayed.If TO_PHYSICAL_LAY () is shielded, you can return normally. The master will give pointers, thank you first! |
|