Save specific values from a file

Asked

Viewed 18 times

0

Contents of the file:

df:bd:89:F1:D4:53 50 20.0

76:1f:02:8f:7d:C8 75 15.0

37:77:ac:10:4e:from 90 -10.5

21:33:ac:63:F7:cd 60 30.0

79:fa:3d:ca:4b:3a 65 25.5

bb:7c:72:ab:ad:ce 35 -5.5

22:db:ed:73:A7:4c 95 20.0

A5:05:92:fa:47:cb 85 35.0

C6:9d:7b:7a:3e:91 15 -25.5

E4:58:0e:30:C2:cf 70 45.5

how I can store the values in front of the hexadecimal codes in a variable(i.e., how can I give Skip of the hexadecimal codes).

  • Do you want to save all the data after the first space? It will always be 2 values or this amount of values may vary?

1 answer

0


For example input provided:

#include <stdio.h>

int main(void) {
    FILE arq;
    float a, b;
    arq = fopen("ficheiro.txt", "r");
    while (fscanf(arq, "%*s %f %f", &a, &b) != EOF)
        printf("t%f\t%f\n", a, b);
    fclose(arq);
    return 0;
}

Note the %*s in the format it indicates for the scanf ignore this entry, in case the first, not assigning to anything.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.