Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2014
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. char a[100];
  2.  
  3. fscanf(fp, "%s %fn", &a, &b);
  4.  
  5. /* reads the list into the arrays name and prices and returns the number of lines (i.e.
  6. elements) that have been read */
  7.  
  8. int read_priceList(const char* path, char names[100][100],
  9. float price[100]){
  10. FILE *fp = fopen(<path>, "r");
  11.  
  12. char a[100];
  13. float b;
  14. int i = 0;
  15.  
  16. if(fp == NULL) {
  17. perror("Error opening File");
  18. return -1;
  19. }
  20. while (!feof(fp) && i < 100) {
  21. fscanf(fp, "%s %fn", &a, &b);
  22. strcpy(names[i], &a);
  23. price [i] = b;
  24. i++;
  25. }
  26. i--;
  27. fclose(fp);
  28. return i;
  29. }
  30.  
  31. char namesPricelist[100][100];
  32. float prices[100];
  33.  
  34. readPricelist(<path>, &namespricelist[0][0], &prices[0]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement