It's a relatively simple thing to do, but I've been having problems separating a string from a file into multiple variables. I've tried strtok and sscanf with delimiters, but I seem to be doing something wrong.
#define MAX 40
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main()
{
char brd_str[26];
char board[26], Res[26], Ind[26], Cap[26];
int i=0, n=0;
FILE *data;
data = fopen ("C:\\datafile.txt", "rt");
fgets(brd_str, 26, data);
sscanf(brd_str,"%d[^,],%f[^,],%e[^,],%e[^,]", &board, &Res, &Ind, &Cap);
printf("%3d %6d %8e %8e", board, Res, Ind, Cap);
fclose(data);
printf("\nPlease enter something for the program to exit");
scanf("%d", &i);
return(0);
}
The string itself looks like this 2,4.57,2.01e-2,5.00e-8
. The comma would be the delimiter in this case. When I compile it I have really large numbers which are incorrect.
This would have to be done multiple times (up to 40), and the variables themselves will be used for calculations.
There seems to be something wrong with the sscanf statement I've put in. I'm not really sure what the problem is.