473,394 Members | 1,759 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

read timings from file to compare

1
I want to read from file like this an find the winner for 500m, 1000m, and so on

But how can I compare the timings column by column( or extract the timing to compare)

Or do I have to declare timing variable as character
Name ;Club ;Age ;500 ;1000 ;1500 ;2000
Alastair Heathcote ;Army RC ;29 ;01:29.7 ;03:00.2 ;04:32.6 ;06:03.0
Richard Egington ;Leander Club ;27 ;01:29.0 ;02:57.9 ;04:26.6 ;05:53.3
Dec 15 '06 #1
1 1409
horace1
1,510 Expert 1GB
I want to read from file like this an find the winner for 500m, 1000m, and so on

But how can I compare the timings column by column( or extract the timing to compare)

Or do I have to declare timing variable as character
Name ;Club ;Age ;500 ;1000 ;1500 ;2000
Alastair Heathcote ;Army RC ;29 ;01:29.7 ;03:00.2 ;04:32.6 ;06:03.0
Richard Egington ;Leander Club ;27 ;01:29.0 ;02:57.9 ;04:26.6 ;05:53.3
assuming you are using C the simplest way is probably to break a line into tokens usinfg strtok
http://www.cplusplus.com/ref/cstring/strtok.html

for example you could start so
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <time.h>
  3. #include <string.h>
  4.  
  5. int main()
  6. {
  7.     FILE *infile;
  8.     char line[100];
  9.     // open file
  10.     if((infile=fopen("data","r")) == NULL) 
  11.         { printf("fileopen fail"); exit(1); }
  12.     fgets(line, 100, infile);               // read line of text
  13.     char *name = strtok(line, ";");         // get name
  14.     printf("name %s\n", name);
  15.     char *club = strtok(NULL, ";");         // get club
  16.     printf("club %s\n", club);
  17.     char *restOfLine = strtok(NULL, "\n");  // get rest line with age, times ,etc
  18.     int age;
  19.     struct tm time={0};
  20.     // get age and time for 500 metres
  21.     sscanf(restOfLine, "%d ;%d:%d.%d", &age, &time.tm_hour, &time.tm_min, &time.tm_sec);
  22.     printf("age %d time %s\n", age, asctime(&time));
  23.      system("pause");
  24. }
  25.  
when run gives
name Alastair Heathcote
club Army RC
age 29 time Sun Jan 00 01:29:07 1900
Dec 15 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: SeanR | last post by:
I have a function to copare two files. It will first copy the original file form a different server to a local temp path and then compare that version to a version that has been restored form tape....
13
by: Don Kim | last post by:
I'm writing a program to read 2,000,000 floating point numbers off a text file, to compute the sum, mean, and median. This is a direct example of Stroustrup's paper. But the program will not...
8
by: Madhusudan Singh | last post by:
Hi I am using time.clock() to get the current time of the processor in seconds. For my application, I need really high resolution but currently seem to be limited to 0.01 second. Is there a way...
2
by: emma middlebrook | last post by:
Hi Is this class and code snippet not good enough to see the differences between having a collection of a value type compared with having a collection of references to a reference type...
14
by: Mark Broadbent | last post by:
Does anybody know what is (factual please -not just guess) the quickest method to read data from a file? I am not interested in the format of the data (i.e. blocks, bytes, string etc) just that the...
5
by: JenHu | last post by:
Hi experts, I wrote a function which retrieves a file in the folder, the file path is : Dim sr As New StreamReader(strFilepath & ReturnFileName) What if I have more than 1 file_name in...
14
by: Zoro | last post by:
My task is to read html files from disk and save them onto SQL Server database field. I have created an nvarchar(max) field to hold them. The problem is that some characters, particularly html...
1
by: MRAB | last post by:
I'm looking at the implementation of regular expressions in Python and wrote a script to test my changes. This is the script: import re import time base = "abc" final = "d"
3
by: sam | last post by:
same as subject?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.