Advertisement
Guest User

Untitled

a guest
Nov 20th, 2011
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. #include <stdio.h>
  2. #include "functions.h"
  3.  
  4. struct Items
  5. {
  6. char code[10];
  7. char description[30];
  8. int stock;
  9. };
  10.  
  11. int main()
  12.  
  13. {
  14. int x=0;
  15. int menu =0;
  16.  
  17. struct Items MyItems[10];
  18.  
  19. ReadFile(MyItems,10);
  20.  
  21. printf("%s %s %d",MyItems[4].code,MyItems[4].description,MyItems[4].stock);
  22.  
  23. }
  24.  
  25.  
  26. // functions.h
  27.  
  28. void ReadFile(struct Items * arr, size_t len)
  29. {
  30. FILE * input;
  31. input = fopen("Items.txt","r");
  32. int x =0;
  33.  
  34. while(!feof(input))
  35. {
  36. fscanf(input,"%[^,],%[^,],%d%*c", arr[x].code,arr[x].description,&arr[x].stock);
  37. x++;
  38. }
  39.  
  40. fclose(input);
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement