Function overloading by passing structure variable

This is a discussion on Function overloading by passing structure variable within the C Programming forums, part of the General Programming Boards category; Hi folks, This is my code. I don't know what error in this. Please help me to correct it Code: ...

  1. #1
    Registered User
    Join Date
    Oct 2011
    Location
    India
    Posts
    53

    Function overloading by passing structure variable

    Hi folks,
    This is my code. I don't know what error in this. Please help me to correct it
    Code:
    struct m_Record
      { 
        int number;
        char S_trancode[3];
        char S_sectype[5];
        char S_secsym[8];
        char D_tdate[9];
        char D_sdate[9];
        int N_quantity;
        int N_trdamt;
        char S_sourcetype[5];
        char S_sourcesym[8];
    }mRecord;
    
    struct inx_Record
    { 
        int number;
        char D_tdate[9]
    }inxRecord;
    
    // read a record from the main
    int ReadRecord(FILE *File, int RecNum, struct m_Record Record)
      { if( fseek(File, RecNum * sizeof(Record), SEEK_SET) == 0 )
          if ( fread(&Record,sizeof(Record),1,File) )
            return 1;
        return 0; }
    
    // read a record from the index file
    int ReadRecord(FILE *File, int RecNum, struct inx_Record Record)
      { if( fseek(File, RecNum * sizeof(Record), SEEK_SET) == 0 )
          if ( fread(&Record,sizeof(Record),1,File) )
            return 1;
        return 0; }
    
    void ListRecords(FILE *File,struct m_Record Record )
    { 
        int i = 0;
            tcnt=0;    
            while (ReadRecord(File,i,Record))
              { 
            if (Record.number != -1)
            {
                printvalues();
                tcnt++;
            }
            
                i++; 
        }
            printf("\n\n");
        printf("Total Records : %ld",tcnt);
        printf("\n\n"); 
    }
    
    void ListRecords(FILE *File,struct inx_Record Record )
    { 
        int i = 0;
            tcnt=0;    
            while (ReadRecord(File,i,Record))
              { 
            if (Record.number != -1)
            {
                printvalues();
                tcnt++;
            }
            
                i++; 
        }
            printf("\n\n");
        printf("Total Records : %ld",tcnt);
        printf("\n\n"); 
    }
    
    /////////// in my main function i will call the ListRecords() function as below
    FILE *File;
    c=toupper(getchar());
        switch(c)
        {
            case '1' :
                File = FileOpen(FNAME);
                break;
            case '2' :
                File = FileOpen(TEMPF);
                break;
        }
            if (!File)
              { 
            printf("Curses foiled again!\n\n");
                exit(-1); 
        }
    if (c=='1')
        ListRecords(File,mRecord);
     else
         ListRecords(File,inxRecord);
    i got the below error
    Code:
    difffiles.c:69:5: error: conflicting types for ‘ReadRecord’
    difffiles.c:62:5: note: previous definition of ‘ReadRecord’ was here
    
    difffiles.c:187:6: error: conflicting types for ‘ListRecords’
    difffiles.c:168:6: note: previous definition of ‘ListRecords’ was here
    Last edited by infantheartlyje; 10-15-2011 at 01:11 AM.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You can't overload functions in C.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by quzah View Post
    You can't overload functions in C.
    Quzah.
    Considering that I merely offered these guys a *conceptual example* there's still an awful lot of my code in there...

    I'm guessing they're trying to do this because *ahem*... they don't know how switch statements work....

    I'm kinda curious to see what happens when they realize Turbo C can only address 32,767 records.

  4. #4
    Registered User
    Join Date
    Oct 2011
    Location
    India
    Posts
    53
    Quote Originally Posted by CommonTater View Post
    they don't know how switch statements work....
    Yeah ! You are Absolutely correct. But not "they". Now its mine Only. Actually i have lot of doubts in switch ? Can you explain me about switch statement ? Can i use switch statement inside a other switch statment?

  5. #5
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    You might just want to be getting a good book on C programming and read it cover to cover...
    I get the feeling the review could save your company.

    To put it bluntly, but in all due respect... have you not yet realized that you are hopelessly out of your depth here?
    Last edited by CommonTater; 10-15-2011 at 02:07 AM.

  6. #6
    Registered User
    Join Date
    Oct 2011
    Location
    India
    Posts
    53
    Quote Originally Posted by CommonTater View Post
    You might just want to be getting a good book on C programming and read it cover to cover...
    I get the feeling the review could save your company.

    To put it bluntly, but in all due respect... have you not yet realized that you are hopelessly out of your depth here?
    Now I'm Learning only. Still i didn't get into the project sir !

  7. #7
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by infantheartlyje View Post
    Now I'm Learning only. Still i didn't get into the project sir !
    That's strange... only three days ago you'd been programming since the '80s...

    Best make up your mind....

  8. #8
    Registered User
    Join Date
    Oct 2011
    Location
    India
    Posts
    53
    Quote Originally Posted by CommonTater View Post
    That's strange... only three days ago you'd been programming since the '80s...
    That older posts are posted by my colleague sir !!

  9. #9
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,306
    Quote Originally Posted by infantheartlyje
    That older posts are posted by my colleague sir !!
    Please create your own account. Refer to the forum guidelines:
    9. Users are allowed only one account unless they are given special permission to hold multiple accounts. Users may not share their account or password with others.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  10. #10
    Registered User
    Join Date
    Aug 2010
    Posts
    231
    You can use one pointer to a function and then put a "real" function, like

    typedef int (*FPtr)(FILE *, int , struct m_Record *);
    ...
    FPtr fptr;
    ...
    fptr = ReadRecord1;
    fptr( fp,1,&record );
    ...
    fptr = ReadRecord2;
    fptr( fp,1,&record );


    Code:
    int ReadRecord(FILE *File, int RecNum, struct m_Record Record)
      { if( fseek(File, RecNum * sizeof(Record), SEEK_SET) == 0 )
          if ( fread(&Record,sizeof(Record),1,File) )
            return 1;
        return 0; }
    This cannot work, there is no call by reference in C, only call by value, so you must use a pointer:

    Code:
    int ReadRecord(FILE *File, int RecNum, struct m_Record *Record)
      { if( fseek(File, (long)RecNum * sizeof(*Record), SEEK_SET) == 0 )
          if ( fread(Record,sizeof(*Record),1,File) )
            return 1;
        return 0; }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. passing structure to function
    By danieldcc in forum C Programming
    Replies: 4
    Last Post: 10-10-2011, 12:17 PM
  2. Passing Function to Structure
    By C-bob in forum C Programming
    Replies: 11
    Last Post: 07-22-2011, 08:36 PM
  3. passing structure variables into function
    By sarathius in forum C Programming
    Replies: 1
    Last Post: 04-08-2008, 12:56 AM
  4. Passing structure to function
    By Sereby in forum C Programming
    Replies: 4
    Last Post: 07-28-2004, 11:05 PM
  5. Passing a structure to a function?
    By Unregistered in forum C++ Programming
    Replies: 6
    Last Post: 12-03-2001, 04:28 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21