Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- // Author: Sam Sampaio
- int main(void) {
- char buffer[256] = {0};
- float v1[256] = {0}, v2[256] = {0}, v3[256] = {0};
- int i =0, j = 0, k = 0, l = 0;
- float *s[3] = {v1,v2,v3};
- int a, b;
- float x[256], y[256];
- FILE *fp;
- if(!(fp = fopen("arquivo.txt", "r"))) {
- perror("Msg: ");
- exit(EXIT_FAILURE);
- }
- while((buffer[i] = fgetc(fp)) != EOF) {
- if(buffer[i] >= '0' &&
- buffer[i] <= '9') {
- if(buffer[i-1] == '.' && buffer[i-2] >= '0'
- && buffer[i-2] <= '9') {
- a = buffer[i] - 48;
- b = buffer[i-2] - 48;
- x[j] = (b << 3) + (b << 1) + a;
- y[j] = x[j] / 10;
- s[l][k] = y[j];
- k++;
- j++;
- }
- }
- if(buffer[i] == '\n') {
- l++;
- k = 0;
- }
- i++;
- }
- fclose(fp);
- for(i=0; i < 3; i++)
- printf("%0.2f ", v1[i]);
- putchar('\n');
- for(i=0; i < 3; i++)
- printf("%0.2f ", v2[i]);
- putchar('\n');
- for(i=0; i < 3; i++)
- printf("%0.2f ", v3[i]);
- putchar('\n');
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement