Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- char a[100];
- fscanf(fp, "%s %fn", &a, &b);
- /* reads the list into the arrays name and prices and returns the number of lines (i.e.
- elements) that have been read */
- int read_priceList(const char* path, char names[100][100],
- float price[100]){
- FILE *fp = fopen(<path>, "r");
- char a[100];
- float b;
- int i = 0;
- if(fp == NULL) {
- perror("Error opening File");
- return -1;
- }
- while (!feof(fp) && i < 100) {
- fscanf(fp, "%s %fn", &a, &b);
- strcpy(names[i], &a);
- price [i] = b;
- i++;
- }
- i--;
- fclose(fp);
- return i;
- }
- char namesPricelist[100][100];
- float prices[100];
- readPricelist(<path>, &namespricelist[0][0], &prices[0]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement