Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.21 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main(void)
  5. {
  6. char line_buffer[1000]; //where new config data is stored
  7. char line_buffer_backup[1000];
  8. char word[100];
  9. char new_word_array[100];
  10. char character;
  11. int word_index = 0;
  12. FILE *config_file_pointer;
  13. FILE *config_file_pointer_backup;
  14. config_file_pointer = fopen("config1.cnf","r");
  15. config_file_pointer_backup = config_file_pointer;
  16.  
  17. char version[500];
  18. char file_path[100];
  19. char cpu_scheduling_code[100];
  20. char quantum_time[100];
  21. char available_memory[100];
  22. char processor_cycle_time[50];
  23. char io_cycle_time[100];
  24. char log_to[100];
  25. char log_file_path[100];
  26.  
  27. //checks if file exists
  28. if (!config_file_pointer)
  29. {
  30. return 0;
  31. }
  32.  
  33. //starts the config file scan
  34. while (feof(config_file_pointer_backup)==0) //until the end of file
  35. {
  36. fscanf(config_file_pointer_backup, "%s", line_buffer); //stores in line_buffer array
  37.  
  38. //version section
  39. if (*line_buffer == 'V')
  40. {
  41. //config_file_pointer_backup = config_file_pointer;
  42. fscanf(config_file_pointer_backup, "%s", version); //jump to string and store in version array
  43. printf("Version: %s \n", version);
  44. }
  45.  
  46. //available memory section
  47. else if (*line_buffer == 'A') //Available is /*
  48. //while (feof(config_file_pointer)==0) //until the end of file
  49. /*while (character != EOF)
  50. {
  51. int iterator = 0;
  52. character = (char)fgetc(config_file_pointer);
  53. if (character == '\0' || character == '\n' || character == ' ')
  54. {
  55. new_word_array[iterator] = *word; // add word to array
  56. ++iterator;
  57. for (int i = 0; i<iterator; i++)
  58. {
  59. printf("%s\n",)
  60. }
  61. printf("%s ", word);
  62. word[word_index] = 0; //reset word index
  63. word_index = 0;
  64. }
  65. else
  66. {
  67. word[word_index++] = character;
  68. word[word_index] = '\0';
  69. }
  70. if (*word == 'P')
  71. {
  72. //printf("%s ", word);
  73. }
  74. //printf("%s ", new_word_array);
  75.  
  76. }
  77.  
  78.  
  79. */
  80.  
  81.  
  82. /*
  83. while (feof(config_file_pointer)==0) //until the end of file
  84. {
  85. fscanf(config_file_pointer, "%s ", line_buffer); //stores in line_buffer array
  86. if(*line_buffer == ':')
  87. {
  88.  
  89. }
  90. //printf("%s ", line_buffer);
  91. //printf("\n");
  92. printf("%s", line_buffer[);
  93. }
  94. */
  95. //only capital A in config
  96. {
  97. //config_file_pointer_backup = config_file_pointer;//reset backup array
  98. fscanf(config_file_pointer_backup, "%s", available_memory); //jump to next word
  99. fscanf(config_file_pointer_backup, "%s", available_memory); //skip '(KB):' and store memory in array
  100. printf("Memory Available: %s \n", available_memory);
  101. }
  102.  
  103. //processor cycle time section
  104. else if (*line_buffer == 'P') //check all 'P words'
  105. {
  106. //config_file_pointer_backup = config_file_pointer;//reset backup array
  107. fscanf(config_file_pointer_backup, "%s", processor_cycle_time); //jump to next word
  108. fscanf(config_file_pointer_backup, "%s", processor_cycle_time); //skip 'cycle'
  109. fscanf(config_file_pointer_backup, "%s", processor_cycle_time); //skip 'time'
  110. fscanf(config_file_pointer_backup, "%s", processor_cycle_time); //skip '(msec):'
  111. if (*processor_cycle_time >= '0' && *processor_cycle_time <= '9') //if word (skipped from all P words starts with number
  112. {
  113. printf("Processor Cycle Time: %s \n", processor_cycle_time);
  114. }
  115. config_file_pointer_backup = config_file_pointer;
  116. }
  117.  
  118.  
  119. //logfile path section
  120. else if (*line_buffer == 'L') //check all 'L words' (Log)
  121. {
  122. fscanf(config_file_pointer_backup, "%s", log_file_path); //jump to next word
  123. if (*log_file_path == 'F') //checks if next word is 'File'
  124. {
  125. fscanf(config_file_pointer_backup, "%s", log_file_path); //skip 'File'
  126. fscanf(config_file_pointer_backup, "%s", log_file_path); //skip 'Path:' and store next word
  127. printf("Log File Path: %s \n", log_file_path);
  128. }
  129. }
  130.  
  131. /*
  132. //file section
  133. else if (*line_buffer == 'F')//check all 'L words' (Log)
  134. {
  135. fscanf(config_file_pointer_backup, "%s", file_path); //jump to next word
  136. printf("File Path: %s\n", file_path);
  137. }
  138. */
  139.  
  140. }
  141. return 0;
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement