Last active
November 10, 2022 17:39
-
-
Save ismnoiet/f8403ab664af4aa8bc85 to your computer and use it in GitHub Desktop.
read text from file in C
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 1 2 3 4 5 6 | |
| 7 8 9 10 11 12 | |
| 13 14 15 16 17 18 | |
| 19 20 21 22 23 24 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | |
| | author : ham ism | | |
| | note : entry file(above ) is used as an entry for this file | | |
| +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | |
| #include<stdio.h> | |
| #include<stdlib.h> | |
| #include<string.h> | |
| struct igrf{ | |
| float n; | |
| float m; | |
| float gnm; | |
| float hnm; | |
| float ugnm; | |
| float uhnm; | |
| }; | |
| int main(){ | |
| FILE *fp1; | |
| char oneword[100]; | |
| struct igrf tab[10]; | |
| float tab2[1000]; | |
| int i; | |
| int j; | |
| char c; | |
| int k=0; | |
| fp1 = fopen("entry","r"); | |
| do { | |
| c = fscanf(fp1,"%s",oneword); /* got one word from the file */ | |
| valeur = strtod(oneword,NULL); | |
| tab2[k] = strtod(oneword,NULL); | |
| k++; | |
| } while (c != EOF); | |
| printf("%i",k); | |
| int m = 0; | |
| int n = 0; | |
| int l=0; | |
| for (m = 0; m < k-1; m +=6) | |
| { | |
| for(n=m;n<m+6;n++){ | |
| if(n % 6 == 0){ | |
| tab[l].n = tab2[n]; | |
| }else if( n % 6 == 1){ | |
| tab[l].m = tab2[n]; | |
| }else if( n % 6 == 2){ | |
| tab[l].gnm = tab2[n]; | |
| }else if(n % 6 == 3){ | |
| tab[l].hnm = tab2[n]; | |
| }else if(n % 6 == 4){ | |
| tab[l].ugnm = tab2[n]; | |
| }else if(n % 6 == 5){ | |
| tab[l].uhnm = tab2[n]; | |
| } | |
| } | |
| l++; | |
| } | |
| printf("\n this is the value : %lf \n ",tab[3].uhnm); | |
| fclose(fp1); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment