Q:

Segmentation fault (core dump) but don't know how to fix it

When trying to input a string of chars, i get a warning
warning: 'doc' may be uninitialized in this function [-Wmaybe-uninitualized]

When i run the code, it only allows me to enter the string itself and then it stops.
I tried compiling the code using an online compiler and it returned `segmentation fault (core dumped). I know something is wrong but i don't know how to fix it. 
#include <stdio.h>
#include <string.h>

typedef struct Pacient{
    char ime_prezime[100];
    int osiguruvanje;
    int broj_pregledi;
}Pacient;

typedef struct MaticenDoktor{
    char ime_prezime[100];
    int broj_pacienti;
    Pacient pacient[200];
    float cena;
}MaticenDoktor;

void najuspesen_doktor(MaticenDoktor *doc, int n){
    int i, j, najgolema_zarabotka=0, najmnogu_pregledi=0, zarabotka, pregledi;
    char najuspesen[100];
    for(i=0; i<n; i++){
        zarabotka=0;
        pregledi=0;
        for(j=0; j<doc[i].broj_pacienti; j++){
            if(doc[i].pacient[j].osiguruvanje==0){
                zarabotka+=doc[i].cena;
                pregledi++;
            }
        }
        if(zarabotka>najgolema_zarabotka){
            najgolema_zarabotka=zarabotka;
            strcpy(najuspesen, doc[i].ime_prezime);
            najmnogu_pregledi=pregledi;
        }
        else if(zarabotka==najgolema_zarabotka){
            if(pregledi>najmnogu_pregledi){
                najgolema_zarabotka=zarabotka;
                strcpy(najuspesen, doc[i].ime_prezime);
                najmnogu_pregledi=pregledi;
            }
        }
    }
    printf("%s %d %d", najuspesen, najgolema_zarabotka, najmnogu_pregledi);
}

int main()
{
    int i, j, n;
    printf("Vnesi broj na doktori\n");
    scanf("%d", &n);
    MaticenDoktor *doc;
    for(i=0; i<n; i++){
        scanf("%s", doc[i].ime_prezime);   //  <---- warning here
        scanf("%d", &doc[i].broj_pacienti);
        scanf("%f", &doc[i].cena);
        for(j=0; j<doc[i].broj_pacienti; j++){
            scanf("%s", doc[i].pacient[j].ime_prezime);
            scanf("%d", &doc[i].pacient[j].osiguruvanje);
            scanf("%d", &doc[i].pacient[j].broj_pregledi);
        }
    }
    najuspesen_doktor(doc, n);
    return 0;
}

Does anyone know how to fix this?

A:

MaticenDoktor *doc; only declares a pointer, and not the full structure (or the array).  You need to initialize it to point to somewhere, where you can warrant there's enough free memory to hold the information.  You can ensure this in several ways:

You can, instead, hold a complete structure in the function body (main in your case, with this similar declaration:
MaticenDoktor doc; /* no pointer, but a full structure variable is declared */
scan("%s", doc.ime_prezime);
...

You can, declare an array of MaticenDoktor structures with the following code:
MaticenDoktor doc[100];  /* now doc is an array with space for 100 MaticenDoktors */
scan("%s", doc[n].ime_prezime); /* n ranges from 0 to 99 max */

You can, if you don't know a priori how many MaticenDoktor you are going to have, and you read it before the loop, with:
MaticenDoktor *doc = malloc(n * sizeof *doc); /* you have doc pointing to an array of n MaticenDoktors */
scan("%s", doc[n].ime_prezime);
...
free(doc); /* after you are completely finished using doc */

You can, if you are short of memory, just declare an array of pointers with space for the maximum, and allocate the structures as you need them:
MaticenDoktor *doc[1000]; /* space for maximum of 1000 pointers to MaticenDoktor */
for (i = 0; i < n && i < 1000; i++) {
    doc[i] = malloc(sizeof *doc[i]); /* size of pointed value, not of pointer */
    scanf("%s", doc[i]->ime_prezime);
    ...
}

and later on
for (i = 0; i < n && i < 1000; i++) {
     free(doc[i]); /* free space used by doc[i] */
}

... and many other ways to organize your memory :)

