Advertisement
lily09290110

fscanf struct

Jan 6th, 2015
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. struct node
  4. {
  5. char s[10];
  6. char s1[10];
  7. double arr[9];
  8. };
  9. struct node name[10];
  10. int main()
  11. {
  12. int i=0,j,a[10]={0};
  13. FILE *f;
  14. f=fopen("b10315020.txt","r");
  15. while((a[i]=fscanf(f,"%s %s ",name[i].s,name[i].s1))!=EOF)
  16. {
  17. printf("\n%s %s ",name[i].s,name[i].s1);
  18. for(j=0;j<9;j++)
  19. {
  20.  
  21. fscanf(f,"%lf",&name[i].arr[j]);
  22. printf("%.2lf ",name[i].arr[j]);
  23. }
  24. i++;
  25. }
  26. fclose(f);
  27. printf("\n\n");
  28. for(j=0;j<9;j++)
  29. printf("%d ",a[j]);
  30. printf("\n");
  31. system("pause");
  32. return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement