1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

what is wrong with my code please help!!

Discussion in 'C' started by imported_compEng, Apr 30, 2011.

  1. imported_compEng

    imported_compEng New Member

    Joined:
    Apr 22, 2011
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    Code:
    char pRead(int f)
    {	
    	FILE *fp;//local pointer of type file
    	int i;
    	char ch;
    	fp= fopen("mytest.txt", "r");
    	for (i = 0; (ch = getc(fp)) != EOF && i < 5; i++)
    	{	
    		if (i==f) return ch;
    	}
    }
    
    the error is :
    Error 2 error C2371: 'pRead' : redefinition; different basic types c:\protocolsc\p1.c 53

    suppose that the argument i sent(f) is from this code
    Code:
    void sender1(void)
    {
    
      frame s;	
      packet buffer;	
      char readArray[4];
       int i, j;
       for (j=0; j<5; j++)
    	{
                      readArray[j]= pRead(j);    //need to fill the array by calling pRead character by character
    	}
      while (true) {
    	 
    		for (i=0; i<=5; i++)
    		{ 
    			buffer.data[i]=readArray[i];    //need to fill the array that a read above in a buffer of typedef (typedef struct {unsigned char data[MAX_PKT];} packet;)
    		}
    	....
      }
    }
     

Share This Page