Hola,
I'm having a major brain fart here.
I am reading in a file from (programName) <input.txt.
And I am using fgets() to grab the each line and I'm dealing with each line.
There are some numbers on the line in the format of 01/01/2011,123.45,56.78,...,23.12
I am trying to grab those numbers (ie 123.45) and convert them into a regular number, atoi() farts out when it hits the . and spits back 123.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
parseFile();
//more work
return 0;
}
void parseFile()
{
while ( fgets(line, 256, stdin) != NULL )
{
//error checking/handling
//dealing with other lines prior to the lines with the data
grabData(line);
}
}
void grabData(char *str)
{
char *delims[] = ",";
char *result = NULL;
result = strtok( str, delims );
//String format going in is in the form of
//date,price1,price2,...,priceN
//sample lines
// 1/31/2012,29.53,26.42,456.48
// 1/30/2012,29.61,26.74,453.01
while ( result != NULL )
{
result = strtok(NULL, delims);//grabs the first price
//how to convert into a number??
//tried scanf() but either I'm not getting it or still confused :S
//Store the number into 'double stockTable[n][m]'
}
}
An suggestions, or a better way in doing it?
Thank You in advance!