-1
#include<stdio.h>
#include<stdlib.h>
#include <string.h>

typedef struct info{
    int vreme_pojavljivanja;
    int vreme_uklanjanja;
    char *tekst;

}Info;

typedef struct clan{
    Clan *prethodni;
    Clan *sledeci;
    Info *prevod;
}Clan;

Clan *novi_clan(char *tekst, int vreme_poc, int vreme_kraj, int max_text);

this is my Strukture.h file

and this is my novi_clan.c file

#include "strukture.h"

Clan *novi_clan(char *tekst,int vreme_poc,int vreme_kraj,int max_text){
    Clan *novi = malloc(sizeof(Clan));


    novi->prethodni = NULL;
    novi->sledeci = NULL;
    novi->prevod = malloc(sizeof(Info));
    novi->prevod->vreme_pojavljivanja = vreme_poc;
    novi->prevod->vreme_uklanjanja = vreme_kraj;
    novi->prevod->tekst = calloc(max_text, sizeof(char));
    strcpy(novi->prevod->tekst, tekst);
    return novi;

}

It gives me errors like Clan is not defined .. And if someone sees an error please reply to it

  • possible duplicate of [C: pointer to struct in the struct definition](http://stackoverflow.com/questions/506366/c-pointer-to-struct-in-the-struct-definition) – sth May 27 '15 at 17:04
  • @НиколаСпајић please "accept" the best answer, that's how SO should work, thanks. – Weather Vane May 27 '15 at 17:18

2 Answers2

1

Change this :

typedef struct clan{
    Clan *prethodni;
    Clan *sledeci;
    Info *prevod;
}Clan;

to

typedef struct clan{
    struct clan *prethodni;
    struct clan *sledeci;
    Info *prevod;
}Clan;

Since you are using the type Clan before it is actually defined.

Eugene Sh.
  • 17,802
  • 8
  • 40
  • 61
1
typedef struct clan{
    Clan *prethodni;
    Clan *sledeci;
    Info *prevod;
}Clan;

When you provide the definition of the struct here, the compiler doesn't yet "know" what Clan is; change it to

typedef struct clan{
    struct clan *prethodni;    // Don't use the typedefed name, it's not yet "available"
    struct clan *sledeci;
    Info *prevod;
}Clan;
user4520
  • 3,401
  • 1
  • 27
  • 50