Hi I was trying to do a type checking in my input file while reading it. I am getting some compile time errors.
Compile time error report is :-
NEW.cpp:26: error: invalid conversion from ‘char*’ to ‘int’
NEW.cpp:26: error: initializing argument 1 of ‘int isdigit(int)’
Line 26 is :- if(isdigit(token))
Here is my code:-
#include<iostream>
#include<fstream>
#include<vector>
#include<string>
using namespace std;
int main() {
FILE *in;
char line[1000];
char *token;
in = fopen("sample.txt","rt+");
if( in == NULL) exit(1);
while(! feof(in)) {
fgets(line, 1000, in);
if (! feof(in))
{
int count=0;
token = strtok(line, " \t\n");
while (token != NULL)
{
if(count++==1) puts(token);
token = strtok(NULL, " \t\n");
if(isdigit(token))
{
cout<<"Is a digit!" << endl;
}
else
{
cout<<"Is not a digit!" << endl;
}
}
}
}
return 0;
}
Here is my sample input file:-
1 323323 BBBBBB CCCCC
2 456557 EEEEEE FFFFF
3 768588 HHHHHH IIIII
2 097760 paste insert
1 895564 mathew horto
I am trying to validate whether the input file has int type in its 2nd field. If not then file format is in correct.
Can somebody help me out ?
Thanks