Like Tree5Likes
  • 1 Post By jimblumberg
  • 4 Post By rags_to_riches

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

This is a discussion on My teachers and I can't find out what is wrong, can you guys help? within the C++ Programming forums, part of the General Programming Boards category; Code: #include <stdlib.h> #include <stdio.h> #pragma pack(1) #define AS 4 //maks 20 void SkriverTilFil(struct student studenter[]) { int i; FILE ...

  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
    2,560
    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
    Sotingen likes this.

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

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,341
    > 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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  7. #7
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,641
    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, 06: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, 07: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, 02: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

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