Search code examples
carraysfilegetc

how to make arrays from txt file C


I got text file with information: (100;200;first).Can anybody tell me how to seperate this information into three arrays: Min=100,Max=200 and Name=first. I have tried this whith

c=getc(inp);

i=atoi(szinput);

but its read 10 for first time and 00 for second... and so on in loop

c saves 10 not 1, so i cant get the right information for arrays...

So the array Min stores 1000 not 100

Thanks.


Solution

  • You could do something like the following

    FILE *file;
    char readBuffer[40];
    int c;
    file = fopen("your_file","r");
    while ((c=getc(file))!= EOF)
    {
        strcat(readBuffer, c);
        if( (char) c == ';')
      //this is the delimiter. Your min, max, name code goes here
    
    }
       fclose(file);