Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main(void)
- {
- char line_buffer[1000]; //where new config data is stored
- char line_buffer_backup[1000];
- char word[100];
- char new_word_array[100];
- char character;
- int word_index = 0;
- FILE *config_file_pointer;
- FILE *config_file_pointer_backup;
- config_file_pointer = fopen("config1.cnf","r");
- config_file_pointer_backup = config_file_pointer;
- char version[500];
- char file_path[100];
- char cpu_scheduling_code[100];
- char quantum_time[100];
- char available_memory[100];
- char processor_cycle_time[50];
- char io_cycle_time[100];
- char log_to[100];
- char log_file_path[100];
- //checks if file exists
- if (!config_file_pointer)
- {
- return 0;
- }
- //starts the config file scan
- while (feof(config_file_pointer_backup)==0) //until the end of file
- {
- fscanf(config_file_pointer_backup, "%s", line_buffer); //stores in line_buffer array
- //version section
- if (*line_buffer == 'V')
- {
- //config_file_pointer_backup = config_file_pointer;
- fscanf(config_file_pointer_backup, "%s", version); //jump to string and store in version array
- printf("Version: %s \n", version);
- }
- //available memory section
- else if (*line_buffer == 'A') //Available is /*
- //while (feof(config_file_pointer)==0) //until the end of file
- /*while (character != EOF)
- {
- int iterator = 0;
- character = (char)fgetc(config_file_pointer);
- if (character == '\0' || character == '\n' || character == ' ')
- {
- new_word_array[iterator] = *word; // add word to array
- ++iterator;
- for (int i = 0; i<iterator; i++)
- {
- printf("%s\n",)
- }
- printf("%s ", word);
- word[word_index] = 0; //reset word index
- word_index = 0;
- }
- else
- {
- word[word_index++] = character;
- word[word_index] = '\0';
- }
- if (*word == 'P')
- {
- //printf("%s ", word);
- }
- //printf("%s ", new_word_array);
- }
- */
- /*
- while (feof(config_file_pointer)==0) //until the end of file
- {
- fscanf(config_file_pointer, "%s ", line_buffer); //stores in line_buffer array
- if(*line_buffer == ':')
- {
- }
- //printf("%s ", line_buffer);
- //printf("\n");
- printf("%s", line_buffer[);
- }
- */
- //only capital A in config
- {
- //config_file_pointer_backup = config_file_pointer;//reset backup array
- fscanf(config_file_pointer_backup, "%s", available_memory); //jump to next word
- fscanf(config_file_pointer_backup, "%s", available_memory); //skip '(KB):' and store memory in array
- printf("Memory Available: %s \n", available_memory);
- }
- //processor cycle time section
- else if (*line_buffer == 'P') //check all 'P words'
- {
- //config_file_pointer_backup = config_file_pointer;//reset backup array
- fscanf(config_file_pointer_backup, "%s", processor_cycle_time); //jump to next word
- fscanf(config_file_pointer_backup, "%s", processor_cycle_time); //skip 'cycle'
- fscanf(config_file_pointer_backup, "%s", processor_cycle_time); //skip 'time'
- fscanf(config_file_pointer_backup, "%s", processor_cycle_time); //skip '(msec):'
- if (*processor_cycle_time >= '0' && *processor_cycle_time <= '9') //if word (skipped from all P words starts with number
- {
- printf("Processor Cycle Time: %s \n", processor_cycle_time);
- }
- config_file_pointer_backup = config_file_pointer;
- }
- //logfile path section
- else if (*line_buffer == 'L') //check all 'L words' (Log)
- {
- fscanf(config_file_pointer_backup, "%s", log_file_path); //jump to next word
- if (*log_file_path == 'F') //checks if next word is 'File'
- {
- fscanf(config_file_pointer_backup, "%s", log_file_path); //skip 'File'
- fscanf(config_file_pointer_backup, "%s", log_file_path); //skip 'Path:' and store next word
- printf("Log File Path: %s \n", log_file_path);
- }
- }
- /*
- //file section
- else if (*line_buffer == 'F')//check all 'L words' (Log)
- {
- fscanf(config_file_pointer_backup, "%s", file_path); //jump to next word
- printf("File Path: %s\n", file_path);
- }
- */
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement