Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define SIZEOFLINE 50
- int main(int argc, char *argv[])
- {
- /*
- argv[0]: Name of source file
- argv[1]: expects log file path
- argv[2]: expects from where to start read data
- argv[3]: expects from where to end read data
- */
- int from = atoi(argv[2]);
- int to = atoi(argv[3]);
- FILE *ptr_file;
- /* ptr_file : is a pointer that poinst to address of file */
- if ((ptr_file = fopen(argv[1],"r")) == NULL)
- {
- printf("Error! opening file");
- /* Program exits if the file pointer returns NULL. */
- }
- int forCounter; /* forCounter: counting for taking data from related part from 22-29 */
- char string[50]; /* string[50]: this is the size of line that read each iteration*/
- char tempString[7]; /* tempString: data(int) taken fist as a string */
- int counter = 0; /* counter is used in dataLog array: for assigning values that taken from log file*/
- double value;
- double dataTakenFromLog[(to-from)];
- /* value used in sscanf : for taken data from log file */
- int counterForArray = 0;
- while(!feof(ptr_file))
- {
- fgets(string,SIZEOFLINE,ptr_file);
- if((counter == from) && (from < to))
- {
- for(forCounter=22;forCounter<29;forCounter++)
- {
- /*it is count 22 to 29 beacuse in our log format data that we want to take is start 22 to 29 */
- if(string[forCounter]==',')
- {
- break;
- }
- tempString[forCounter-22]=string[forCounter]; /*value saved as temp to tempString*/
- }
- sscanf(tempString,"%lf",&value); /*scanned string for take double value that consist in tempString*/
- printf("%.1lfn",value);
- dataTakenFromLog[counterForArray] = value;
- counterForArray++;
- from++;
- }
- counter++;
- }
- printf("datasize is : %dn", counter);
- int s;
- for(s=0;s<(to-from);s++)
- {
- printf("dataTakenFromLog[%d] is %.1lfn",s,dataTakenFromLog[s]);
- }
- fclose(ptr_file);
- }
- #include <stdio.h>
- #include <stdlib.h>
- #define SIZEOFLINE 50
- int main(int argc, char *argv[])
- {
- /*
- argv[0]: Name of source file
- argv[1]: expects log file path
- argv[2]: expects from where to start read data
- argv[3]: expects from where to end read data
- */
- int from = atoi(argv[2]);
- int to = atoi(argv[3]);
- FILE *ptr_file;
- /* ptr_file : is a pointer that poinst to address of file */
- if ((ptr_file = fopen(argv[1],"r")) == NULL)
- {
- printf("Error! opening file");
- /* Program exits if the file pointer returns NULL. */
- }
- int forCounter; /* forCounter: counting for taking data from related part from 22-29 */
- char string[50]; /* string[50]: this is the size of line that read each iteration*/
- char tempString[7]; /* tempString: data(int) taken fist as a string */
- int counter = 0; /* counter is used in dataLog array: for assigning values that taken from log file*/
- double value;
- int sizeOfData = to-from; **i changed only this area just declaration differently**
- double dataTakenFromLog[sizeOfData];
- /* value used in sscanf : for taken data from log file */
- int counterForArray = 0;
- while(!feof(ptr_file))
- {
- fgets(string,SIZEOFLINE,ptr_file);
- if((counter == from) && (from < to))
- {
- for(forCounter=22;forCounter<29;forCounter++)
- {
- /*it is count 22 to 29 beacuse in our log format data that we want to take is start 22 to 29 */
- if(string[forCounter]==',')
- {
- break;
- }
- tempString[forCounter-22]=string[forCounter]; /*value saved as temp to tempString*/
- }
- sscanf(tempString,"%lf",&value); /*scanned string for take double value that consist in tempString*/
- printf("%.1lfn",value);
- dataTakenFromLog[counterForArray] = value;
- counterForArray++;
- from++;
- }
- counter++;
- }
- printf("datasize is : %dn", counter);
- int s;
- for(s=0;s<sizeOfData;s++)
- {
- printf("dataTakenFromLog[%d] is %.1lfn",s,dataTakenFromLog[s]);
- }
- fclose(ptr_file);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement