I'm trying to parse a file to apply the banker's algorithm to in unix shell. The format of the file is as follows:
# resources
# processes
Process_# R0_alloc R1_alloc .. R0_max R1_max .. R0_avail R1_avail .. [R0_req R1_req ..]
What I've got so far is
cin>>argv[1];
ifstream input(argv[1]);
string line;
while(getline(input, line))
{
// parse the string into different sections divided by a space and put those in arrays
}
Sample input should be something like this:
4
8
0 1 2 3 4 4 4 4 4 0 0 0 1 1 2 1 0
1 4 3 2 1 4 4 4 4 0 2 2 0
2 0 0 0 3 1 2 2 3 0 0 1 0
3 3 0 0 0 4 0 0 2 0 0 0 1
4 1 1 2 1 3 3 2 4 0 0 0 1
5 0 0 2 2 0 0 2 3 0 0 0 2
6 2 0 2 0 2 0 2 2 1 0 0 0
7 1 1 1 1 2 2 2 1 1 1 0 0
I don't know how to convert the string into integers and put them in arrays. Also the last array 'req' might not be specified, I don't know how to handle that case either.
Thanks!

New Topic/Question
Reply



MultiQuote



|