Advertisement
huyhung94

Đọc file _ Sa Phi

Feb 25th, 2015
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.88 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5.  
  6.  
  7. typedef struct{
  8.   char text[30];
  9.   int num1, num2, num3;
  10. }sa_phi;
  11. sa_phi sp[999];
  12.  
  13. int main(){
  14.    
  15.     FILE *f;
  16.     int i=0, num_of_file=0;
  17.    
  18.     f = fopen("readme.txt","rt");
  19.     while(!feof(f)){       
  20.         char tmp[999], *p;
  21.         fgets(tmp,90,f); // Doc tung dong
  22.         char **b = (char **) malloc(100*sizeof(char));
  23.         p = strtok(tmp," \"");
  24.         int index=0;
  25.         //Luu chuoi da duoc tach vao mang b
  26.         while(p!=NULL){
  27.             b[index] = p;
  28.             index++;
  29.             p = strtok(NULL," \"");
  30.         }
  31.         //Chuyen doi so    
  32.         strcpy(sp[i].text, b[0]);
  33.         sp[i].num1 = atoi(b[1]);
  34.         sp[i].num2 = atoi(b[2]);
  35.         sp[i].num3  = atoi(b[3]);                      
  36.         i++; //Dem So dong`
  37.     }
  38.     printf("So dong doc duoc la: %d\n",i);
  39.     num_of_file = i;
  40.     for(i=0;i<num_of_file;i++){
  41.         printf("%s %d %d %d\n",sp[i].text, sp[i].num1, sp[i].num2, sp[i].num3);
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement