Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.40 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define SIZEOFLINE 50
  4.  
  5. int main(int argc, char *argv[])
  6. {
  7. /*
  8. argv[0]: Name of source file
  9. argv[1]: expects log file path
  10. argv[2]: expects from where to start read data
  11. argv[3]: expects from where to end read data
  12.  
  13. */
  14. int from = atoi(argv[2]);
  15. int to = atoi(argv[3]);
  16.  
  17.  
  18.  
  19. FILE *ptr_file;
  20. /* ptr_file : is a pointer that poinst to address of file */
  21. if ((ptr_file = fopen(argv[1],"r")) == NULL)
  22.  
  23. {
  24. printf("Error! opening file");
  25. /* Program exits if the file pointer returns NULL. */
  26. }
  27.  
  28. int forCounter; /* forCounter: counting for taking data from related part from 22-29 */
  29. char string[50]; /* string[50]: this is the size of line that read each iteration*/
  30. char tempString[7]; /* tempString: data(int) taken fist as a string */
  31. int counter = 0; /* counter is used in dataLog array: for assigning values that taken from log file*/
  32. double value;
  33.  
  34. double dataTakenFromLog[(to-from)];
  35. /* value used in sscanf : for taken data from log file */
  36. int counterForArray = 0;
  37.  
  38. while(!feof(ptr_file))
  39. {
  40.  
  41. fgets(string,SIZEOFLINE,ptr_file);
  42.  
  43. if((counter == from) && (from < to))
  44. {
  45.  
  46. for(forCounter=22;forCounter<29;forCounter++)
  47. {
  48. /*it is count 22 to 29 beacuse in our log format data that we want to take is start 22 to 29 */
  49. if(string[forCounter]==',')
  50. {
  51. break;
  52. }
  53.  
  54. tempString[forCounter-22]=string[forCounter]; /*value saved as temp to tempString*/
  55. }
  56.  
  57. sscanf(tempString,"%lf",&value); /*scanned string for take double value that consist in tempString*/
  58. printf("%.1lfn",value);
  59.  
  60. dataTakenFromLog[counterForArray] = value;
  61.  
  62. counterForArray++;
  63. from++;
  64. }
  65. counter++;
  66. }
  67.  
  68. printf("datasize is : %dn", counter);
  69. int s;
  70. for(s=0;s<(to-from);s++)
  71. {
  72.  
  73. printf("dataTakenFromLog[%d] is %.1lfn",s,dataTakenFromLog[s]);
  74.  
  75. }
  76.  
  77. fclose(ptr_file);
  78.  
  79. }
  80.  
  81. #include <stdio.h>
  82. #include <stdlib.h>
  83. #define SIZEOFLINE 50
  84.  
  85. int main(int argc, char *argv[])
  86. {
  87. /*
  88. argv[0]: Name of source file
  89. argv[1]: expects log file path
  90. argv[2]: expects from where to start read data
  91. argv[3]: expects from where to end read data
  92.  
  93. */
  94. int from = atoi(argv[2]);
  95. int to = atoi(argv[3]);
  96.  
  97.  
  98.  
  99. FILE *ptr_file;
  100. /* ptr_file : is a pointer that poinst to address of file */
  101. if ((ptr_file = fopen(argv[1],"r")) == NULL)
  102.  
  103. {
  104. printf("Error! opening file");
  105. /* Program exits if the file pointer returns NULL. */
  106. }
  107.  
  108. int forCounter; /* forCounter: counting for taking data from related part from 22-29 */
  109. char string[50]; /* string[50]: this is the size of line that read each iteration*/
  110. char tempString[7]; /* tempString: data(int) taken fist as a string */
  111. int counter = 0; /* counter is used in dataLog array: for assigning values that taken from log file*/
  112. double value;
  113.  
  114. int sizeOfData = to-from; **i changed only this area just declaration differently**
  115. double dataTakenFromLog[sizeOfData];
  116.  
  117. /* value used in sscanf : for taken data from log file */
  118. int counterForArray = 0;
  119.  
  120. while(!feof(ptr_file))
  121. {
  122.  
  123. fgets(string,SIZEOFLINE,ptr_file);
  124.  
  125. if((counter == from) && (from < to))
  126. {
  127.  
  128. for(forCounter=22;forCounter<29;forCounter++)
  129. {
  130. /*it is count 22 to 29 beacuse in our log format data that we want to take is start 22 to 29 */
  131. if(string[forCounter]==',')
  132. {
  133. break;
  134. }
  135.  
  136. tempString[forCounter-22]=string[forCounter]; /*value saved as temp to tempString*/
  137. }
  138.  
  139. sscanf(tempString,"%lf",&value); /*scanned string for take double value that consist in tempString*/
  140. printf("%.1lfn",value);
  141.  
  142. dataTakenFromLog[counterForArray] = value;
  143.  
  144. counterForArray++;
  145. from++;
  146. }
  147. counter++;
  148. }
  149.  
  150. printf("datasize is : %dn", counter);
  151. int s;
  152. for(s=0;s<sizeOfData;s++)
  153. {
  154.  
  155. printf("dataTakenFromLog[%d] is %.1lfn",s,dataTakenFromLog[s]);
  156.  
  157. }
  158.  
  159. fclose(ptr_file);
  160.  
  161. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement