How do I read and separate save data separated by semicolons and commas?

-2

Good night everyone, I'm doing a program in c that has to read a file and save the data, each line of the file representing the data of a client, how do I save the data by separating it by "; " and ","? The file to read is:

.txt file 1 ; Family; 2 ; 2 ; I 3, M 3, BR 4, AL 2 2 ; Individual; 1 ; I 2, M 2 3; Family; 1 ; 0; AB 2, AM 3, AL 5, BR 2 4; Individual; 0; AL 3, BR 2

    
asked by anonymous 23.06.2017 / 22:27

1 answer

0

See an example here:

Dados ficheiro:  
emilio silva ; 25 , 2 , 2017
carla patricia , 3 , 4 , 2016
Silvia Pereira ; 25 , 8 , 2015
Miguel Antonio, 7 , 8 , 2014  

Code:

int main(void){

    FILE *fp = fopen("testo.txt", "r");

    char linha[100];
    int dia, mes, ano;
    char nome[50], apelido[50];

    if(fp != NULL) {

        while(fgets(linha, 100, fp)){

            sscanf(linha, "%s %s ; %d , %d , %d", nome, apelido, &dia, &mes, &ano);

            printf("\n%s %s, %d %d %d\n", nome, apelido, dia, mes, ano);
        }
    } else {
        printf("\nErro");
    }


    system("pause");
    return 0;
}
    
24.06.2017 / 01:49