In a forest n animals has homes. Each home has m racks, each rack for each of the m products which the animals can buy from the shop. From the shop, only the king can buy and only in the first day of the month. The king needs to know at the end of the month how much food he must buy. So he goes to all the animals to take the command. Then, he goes to the shop to buy. Each products are being selled at piece.
To calculate:
1. How much food the animals have after the king returned from the shop?
2. How much an animal should pay, if the prieces for each m food are known?
3. How many days an animal should work for paying? The animals are not paying for anything else and an animal, for each day of work, it receives g dollars.
From a file animals.in I have to read the necessary data.
On the first row is an integer which represents how many dollars an animal receives for a day of work.
On the next row there are two numbers separated by a space. A number,n , the number of the animals and the number of racks, m, from each house.
On the next n rows there is the ammount of the food that each animal has, given by separated numbers. M numbers on each row.
On the next n rows there are the commands for m type of foods that each animal made. M numbers on each row.
On the last line the are the prieces for each type of food. M numbers.
The results should be displayed in animals.out.
I want JUST to read the data and to assign the numbers to some variables in my C program and print them to monitor. I will manage from there.
I wrote the file like this:
20
5 3
2 3 4
5 7 8
10 24 3
8 5 1
2 4 8
5 8 3
1 4 6
8 9 5
3 4 1
5 7 9
150 200 350
Here is what I tried:
//functions.c
#include<stdio.h>
#include"header.h"
#include<stdlib.h>
#include<string.h>
void read(double a[][200])
{
char line[250];
int v[200];
int i;
//int g;
FILE *in;
in = fopen("animals.in", "r");
if(in==0)
{
printf("Eroare.\n");
exit(EXIT_FAILURE);
}
//fscanf(in, "%d", &g);
while(fgets(line,sizeof(line),in)!=NULL)
{
v[i]=atoi(line);
i++;
//v[i]=atoi(ptr);
//i++;
//ptr=strtok(NULL," ");
}
int qwer;
qwer=i;
for(i=0;i<qwer;i++)
{
printf("\nThe number %d of %d is: %d", i+1,qwer,v[i]);
}
printf("\n\n");
//printf("%d", g);
/*
fscanf(in, "n=%d, m=%d", &n, &m);
for(i=0;i<n;i++)
for(j=0;j<m;j++)
fscanf(in, "%lf", &a[i][j]);
printf("%d %d %d", g,n,m);
for(i=0;i<n;i++)
for(j=0;j<m;j++)
printf("%lf", a[i][j]);
*/
}
I am calling the function read from a file main.c
I do not know what to do!!!
PLEASE HELP ME!!!
Thanks in advance!!!