Been playing around with c trying to parse a csv file.
Right now I'm trying to implement a function to check where or not a string is only a double so I can then convert it. However I'm having some problems in the .h file getting "syntax error before bool" and "data definition has no type or storage class"
#ifndef MSGR_H
#define MSGR_H
#include <stdio.h>
#include <stdlib.h>
typedef struct Entry
{
char *str;
int iVal;
} Entry;
int NumRows(char fileName[]);
int NumColumns(char fileName[]);
void TokenizeLine(int x; int y; char currentLineStr[], Entry eTable[x][y], int yIndex, int x, int y);
*** bool IsDouble(const char *str);*** (problem is supposedly here)
#endif
Below is the function itself.
bool IsDouble(const char *str)
{
char *endPtr = 0;
bool flag = true;
strtod(str, &endPtr);
if(*endPtr != '\0' || endPtr == str);
flag = false;
return flag;
}
Appreciate any and all input.
There is no bool
in C unless you use at least C99 and include <stdbool.h>
.
Common practice: return int
, 0
evaluates to false, anything else (normally 1
) to true when used as a boolean.
Code:
int IsDouble(const char *str)
{
char *endPtr = 0;
strtod(str, &endPtr);
if(*endPtr != '\0' || endPtr == str)
{
return 0;
}
return 1;
}
(There was also a superfluous semicolon ...)