Thread: cannor convert parameter...

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    49

    cannor convert parameter...

    I'm having this error occur and I'm not sure how to resolve it...

    Code:
    error C2664: 'readfile' : cannot convert parameter 1 from 'employee [14]' to 'int *'
    here is where it is pointing to...
    Code:
    readfile(records, buf);
    and here is the readfile portion...
    Code:
        do{
            fgets(buf,200,fPtr);
            sscanf(buf, "%d %s %f %d", &records[i].id, &records[i].name, &records[i].pr, &records[i].csalary);
    tks in advance
    Code this

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    I'm guessing the records array is of type struct employee. What does the prototype for readfile() look like? It looks like it should be void readfile(struct employee *records, char *buf);
    If you understand what you're doing, you're not learning anything.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    Check your prototype / definition of the function

    > 'employee [14]'
    This is what you tried to call it with

    > 'int *'
    This is what it expected.

    Solution: make them the same type
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Sep 2003
    Posts
    49
    Quote Originally Posted by itsme86
    I'm guessing the records array is of type struct employee. What does the prototype for readfile() look like? It looks like it should be void readfile(struct employee *records, char *buf);

    that seem to have worked, now I have another error..

    Code:
     error C2228: left of '.csalary' must have class/struct/union type

    from here ..
    Code:
    sscanf(buf, "%d %s %f %d", &records[i].id, &records[i].name, &records[i].pr, &records[i].csalary);
    is this an error in my declaration?
    Code this

  5. #5
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    I think it would help if you showed us your struct employee definition.
    If you understand what you're doing, you're not learning anything.

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    Re-reading your book on what a struct is would help as well.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Registered User
    Join Date
    Sep 2003
    Posts
    49
    Quote Originally Posted by itsme86
    I think it would help if you showed us your struct employee definition.
    Code:
    struct employee 
    {
        int id;
        char name[10];
        float pr;
        int csalary;
        int raise;
        double rate;
        int nsalary;
    };
    Code this

  8. #8
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You sure do like to provide the absolute minimum in information, don't you? You never show what exactly 'employee' is. Is it an array? Is it a single instance? Is it even anything to do with your structure? We wouldn't know, because you never provide that information.

    Do you show us the function prototype for 'readfile' so we can see how it's set up? No. Do you show us the variable declarations of the variables you're passing to it? No again.

    If you want some real help, try actually helping us help you, instead of sitting around with your head up your ass wondering why you can't see clearly.

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

  9. #9
    Registered User
    Join Date
    Sep 2003
    Posts
    49
    Quote Originally Posted by quzah
    You sure do like to provide the absolute minimum in information, don't you? You never show what exactly 'employee' is. Is it an array? Is it a single instance? Is it even anything to do with your structure? We wouldn't know, because you never provide that information.

    Do you show us the function prototype for 'readfile' so we can see how it's set up? No. Do you show us the variable declarations of the variables you're passing to it? No again.

    If you want some real help, try actually helping us help you, instead of sitting around with your head up your ass wondering why you can't see clearly.

    Quzah.

    calm down there killer..i just didnt want to post the whole code...but here it is..

    FYI: trail.txt is a file that consist of employee's


    Code:
    ...
    Last edited by SpEkTrE; 02-17-2005 at 12:48 PM.
    Code this

  10. #10
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Much better, now all you need to do is learn to indent. Oh, and you may also want to actually pay attention to your compiler:
    Code:
    void readfile(struct employee *records, char *buf);
    
    ...
    
    void readfile(int *records, char *buf)
    {
        FILE *fPtr; 
        int i;
        do{
            fgets(buf,200,fPtr);
            sscanf(buf, "%d %s %f %d", &records[i].id, &records[i].name, &records[i].pr, &records[i].csalary);
        }
        while (!(feof(fPtr)));
    }
    While you're at it, read the FAQ on why using feof to control loops is a bad idea.

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

  11. #11
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Anoter thing is, you'll need to either pass fPtr from main to readfile() or open the file in readfile(). You declare an fPtr in readfile() but it isn't initialized. The one in main() is the one that's initialized.
    If you understand what you're doing, you're not learning anything.

  12. #12
    Registered User
    Join Date
    Sep 2003
    Posts
    49
    I'm almost there...

    But I believe it is not reading the data from the first file. Mainly because I have output of zero's. I did try to place a print statement just after the fgets and the sscanf, but I come up with the same outcome...

    Code:
    void readfile(struct employee *records, char *buf)
    {
    	FILE *fPtr; 
    	int i;
    	fPtr = fopen("lab2.txt", "r");
    	do{
            fgets(buf,200,fPtr);
    		sscanf(buf, "%d %s %f %d", &records[i].name, &records[i].name, &records[i].pr, &records[i].csalary);
    	}
    	while (!(feof(fPtr)));
    }
    looks okay to me, but of course, its not
    Code this

  13. #13
    Hello,

    Small glitch:
    Code:
    sscanf(buf, "%d %s %f %d", &records[i].name, &records[i].name, ...
    Looks like name is in there twice, with a %s and %d flag.


    - Stack Overflow
    Segmentation Fault: I am an error in which a running program attempts to access memory not allocated to it and core dumps with a segmentation violation error. This is often caused by improper usage of pointers, attempts to access a non-existent or read-only physical memory address, re-use of memory if freed within the same scope, de-referencing a null pointer, or (in C) inadvertently using a non-pointer variable as a pointer.

  14. #14
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    You might want to check the return value of fopen() to make sure it didn't fail. If it did, fPtr would be NULL after the call to fopen().

    Also, why did you delete your code from your previous post?
    If you understand what you're doing, you're not learning anything.

  15. #15
    Hello,

    C++ library reference: fopen()


    - Stack Overflow
    Segmentation Fault: I am an error in which a running program attempts to access memory not allocated to it and core dumps with a segmentation violation error. This is often caused by improper usage of pointers, attempts to access a non-existent or read-only physical memory address, re-use of memory if freed within the same scope, de-referencing a null pointer, or (in C) inadvertently using a non-pointer variable as a pointer.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. my error is storage class specified for parameter
    By meli in forum C Programming
    Replies: 5
    Last Post: 03-27-2009, 12:06 PM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. cannot start a parameter declaration
    By Dark Nemesis in forum C++ Programming
    Replies: 6
    Last Post: 09-23-2005, 02:09 PM
  5. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM