• Advertisement
Sign in to follow this  

4 layer reference model for communication error

This topic is 2928 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
Quote:
buf = new int[fr];
What are you expecting that line to do?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement