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
1 1409
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 -
#include <stdio.h>
-
#include <time.h>
-
#include <string.h>
-
-
int main()
-
{
-
FILE *infile;
-
char line[100];
-
// open file
-
if((infile=fopen("data","r")) == NULL)
-
{ printf("fileopen fail"); exit(1); }
-
fgets(line, 100, infile); // read line of text
-
char *name = strtok(line, ";"); // get name
-
printf("name %s\n", name);
-
char *club = strtok(NULL, ";"); // get club
-
printf("club %s\n", club);
-
char *restOfLine = strtok(NULL, "\n"); // get rest line with age, times ,etc
-
int age;
-
struct tm time={0};
-
// get age and time for 500 metres
-
sscanf(restOfLine, "%d ;%d:%d.%d", &age, &time.tm_hour, &time.tm_min, &time.tm_sec);
-
printf("age %d time %s\n", age, asctime(&time));
-
system("pause");
-
}
-
when run gives
name Alastair Heathcote
club Army RC
age 29 time Sun Jan 00 01:29:07 1900
Sign in to post your reply or Sign up for a free account.
Similar topics
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....
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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"
|
by: sam |
last post by:
same as subject?
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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...
| |