Thread: My teachers and I can't find out what is wrong, can you guys help?

  1. #1
    Registered User
    Join Date
    Nov 2012
    Posts
    3

    Exclamation My teachers and I can't find out what is wrong, can you guys help?

    Code:
    #include <stdlib.h>
    #include <stdio.h>
    #pragma pack(1)
    #define AS 4 //maks 20
    
    
    
    
    
    
    void SkriverTilFil(struct student studenter[])
    
    {
        int i;
    
        FILE *f;
        f=fopen("c:\\work\\Peeps.txt","wb");
    
        
            
            
            fwrite(studenter,1,sizeof(studenter),f);
            fclose(f);
            
                
    }
    
    int main(int argc, char * argv[])
    {
        
    struct date
        {
            unsigned int nMonthday  :5;
            unsigned int nMonth        :4;
            unsigned int nYear        :16;
    
        };
    
    
    struct student
        {
            char name[80];
            char Etternavn[80];
            struct date fodt;
        }studenter[20];
    
    
        int i,value;
    
        
    
        for(i=0;i<AS;i++)
            {
                printf("Skriv inn Fornavnet på person nr. %d: ",i+1);
                scanf("%s",&studenter[i].name);
        
                printf("Skriv inn Etternavn til person nr. %d: ",i+1);
                scanf("%s", &studenter[i].Etternavn);
    
                printf("Skriv inn datoen du ble fodt, start med dag deretter  maaned og aar, trykker mellom hver av de: ");
                scanf("%d",&value);
                studenter[i].fodt.nMonthday=value;
                scanf("%d",&value);
                studenter[i].fodt.nMonth=value;
                scanf("%d",&value);
                studenter[i].fodt.nYear=value;
            }
    
        SkriverTilFil(&studenter[AS]);
    
    
        system("PAUSE");
        return 0;
    
    }

  2. #2
    Registered User
    Join Date
    Nov 2012
    Location
    Humenne, Slovakia
    Posts
    4
    how do we have to help you when u won't describe your error at all? what's not working? what's bad? do you get any compilation errors? or what?

  3. #3
    Registered User
    Join Date
    Nov 2012
    Posts
    3
    error C2664: 'SkriverTilFil' : cannot convert parameter 1 from 'main::student *' to 'student []'
    Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast.

    Sorry, forgot to post that. This is the error i get. I am very new in this, so i have no idé what it means.
    Thanks in advance

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Code:
    int main(int argc, char * argv[])
    {
     
    struct student
        {
            char name[80];
            char Etternavn[80];
            struct date fodt;
        }studenter[20];
     
        SkriverTilFil(&studenter[AS]);

    Since you defined your student structure inside of main, how will your SkriverTilFil() know anything about this structure? Your structure needs to be defined before it can be used, and by defining this structure in a function it is only available inside that function. No other function will be able to use it. So I recommend you define your structures outside of any function and before any function that will require this structure.

    Jim

  5. #5
    Registered User
    Join Date
    Nov 2012
    Posts
    3
    Thanks I will try that ^^

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > error C2664: 'SkriverTilFil' : cannot convert parameter 1 from 'main::student *' to 'student []'
    > Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast.
    All this guff points to you compiling your C code with a C++ compiler.

    But then again, you did post in C++, so perhaps writing C is the mistake.

    Decide which language you're writing in, select the appropriate compiler (say by calling the source file prog.c rather than prog.cpp), and post on the correct forum.
    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
    Dec 2007
    Posts
    2,675
    My teachers and I can't find out what is wrong, can you guys help
    That doesn't bode well.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Any teachers here?
    By John_ in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 02-15-2006, 07:03 PM
  2. can't find ronin, so can you guys help :D
    By mellisa in forum C++ Programming
    Replies: 6
    Last Post: 01-26-2003, 08:23 PM
  3. Can someone find out what i'm doing wrong?
    By QuincyEQ in forum C Programming
    Replies: 2
    Last Post: 08-15-2002, 11:22 AM
  4. I hope you guys find my new site useful
    By moogle33 in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 03-27-2002, 03:29 AM
  5. Help me find out what's wrong
    By biosx in forum C Programming
    Replies: 4
    Last Post: 08-15-2001, 12:37 PM