4 layer reference model for communication error

Started by
1 comment, last by cache_hit 14 years, 1 month ago
I'm trying to simulate a simple 4 layer reference model for communication between two hosts. However, I seem to be getting a simple error, which I can't figure out. The Part of my code is: int* layer4(int* buf,int* bufsize ,int flag) { if(flag == 1) //Transmit { //Read data from file into an array FILE *fr; int rr; fr = fopen( "sendfile.txt", "r" ); fseek(fr,0,SEEK_END); int filesize = ftell(fr); rewind(fr); buf = new int[fr]; int i=0; while((rr = getc(fr)) != EOF) { buf = rr - 48; i = i+1; } (*bufsize) = filesize; fclose(fr); return buf; } else //Receive { //Store data in file FILE *fw; fw = fopen("receivefile.txt","w"); char* x; x = new char; for(int i=0; i<(*bufsize); i++) { itoa(buf,x,2); fputs(x,fw); } fclose(fw); } } And the following error I'm getting refers to buf = new int[fr]; In function `int* layer4(int*, int*, int)': expression in new-declarator must have integral or enumeration type
Advertisement
Quote:buf = new int[fr];
What are you expecting that line to do?
fr is a FILE*. You've specified this inside the [] of the new declarator. You're saying you want to allocate an array of size fr, which doesn't make any sense because fr isn't a number.

This topic is closed to new replies.

Advertisement