Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7581567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:14:00+00:00 2026-05-30T18:14:00+00:00

Okay, I have a main source called main.c , a header file called test.h

  • 0

Okay, I have a main source called main.c, a header file called test.h, and another class called handBeraknare.c.
Im trying to make my code a bit more readable by transfeering some of my methods to the class handBeraknare.c.

So in main.c i have a struct that looks like this:

typedef struct kort{
  int draget;
  char farg;
  int nummer;
  struct kort *next;
  }kort; `

In main.c i create a couple of these using kort k=(kort*)malloc(sizeof(kort)); and put them into an array. What im trying to achive is to send this array of kort to a function in handBeraknare.c but I get some sort of weird error "in file included from handBeraknare.c".

Im gussing this has to do with the headerfile now knowing what "kort" is (my struct). Anyway, here’s some of the code:

// in test.h
int beraknaFarg(kort kortHand[]);



// in handBeraknare.c
#include <stdio.h>
#include "test.h"
int beraknaFarg(kort kortHand[]){
 char c = kortHand[0].farg;
    int i;
    for (i=1;i<5;i++){
        if (kortHand[i].farg!=c){
                                 printf("inte färg");
                                 system("pause");
           //Spelaren har inte färg. Retunera 0
           return 0;
           }
         }
      //Spelaren har färg. Retunera 1 
       printf("!!!!färg");
                                 system("pause");  
      return 1;
}


//part of the main class. Calling function test() 
// which calls the method beraknaHand which exists in handBeraknare.c

#include "test.h"
...

int main(int argc, char *argv[])
{
  test();
}

// the testfunction in my mainclass
void test(){
       char farg[4]={'S','K','R','J'};
       int nummer[14]={0,2,3,4,5,6,7,8,9,10,11,12,13,14};
       kort kortArray[52];
       kort kortHand[5]; 
                  kort *k;
                  k=(kort*)malloc(sizeof(kort));              
                  k->farg='s';
                  k->nummer=5;
                  kortHand[0]=*k;

                  k->farg='s';
                  k->nummer=11;
                  kortHand[1]=*k;

                  k->farg='s';
                  k->nummer=12;
                  kortHand[2]=*k;

                  k->farg='s';
                  k->nummer=11;
                  kortHand[3]=*k;

                  k->farg='s';
                  k->nummer=9;
                  kortHand[4]=*k;
    beraknaFarg(kortHand);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T18:14:01+00:00Added an answer on May 30, 2026 at 6:14 pm

    Make test.h to read

    typedef struct kort{ 
          int draget; 
          char farg; 
          int nummer; 
          struct kort *next; 
          } kort;
    int beraknaFarg(kort kortHand[]); 
    

    and remove the typedef from main.c

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay I have updated my code quite a bit. I am getting a new
Okay so I have the following Code which appends a string to another in
Okay, this is a bit messy: I'm using Netbeans, and I have a main
Okay, so you have a load of methods sprinkled around your system's main class.
Okay here's the program I have typed up(stdio.h is included also): /* function main
Okay I have a series of objects based on a base class which are
Okay I have updated my code a little, but I am still not exactly
Okay so I have a scenario similar to the below code, I have a
Okay so my question is this. Say I have a simple C++ code: #include
Okay, I am having trouble with the following piece of code (in a header

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.