Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int m = 0; // Total of Processes
- int n = 0; // Total of Resources
- int i = 0, j = 0;
- int S[100][100]; // Matrix
- FILE *file = fopen("TestCase06.txt", "r");
- if(file == NULL)
- {
- printf("The file was not successfully opened.\n");
- exit(1);
- }
- else
- {
- // Count row and column(m and n)
- int stop = 0;
- char ch;
- while(!feof(file))
- {
- ch = fgetc(file);
- if(ch == '\n')
- {
- m++;
- stop = 1;
- }
- if(stop != 1)
- if(ch != '\n' && ch != ',')
- n++;
- }
- // Input the matrix
- file = fopen("TestCase06.txt", "r");
- while(!feof(file))
- {
- ch = fgetc(file);
- if(ch != ',' && ch != '\n')
- {
- S[i][j] = (int)(ch - '0');
- }
- if(ch == '\n')
- {
- i++;
- j = 0;
- }
- else if(ch != ',')
- {
- j++;
- }
- }
- }
- fclose(file);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement