I have a question regarding char pointers.
I am reading a file in C, using fgets
. This is a short overview so you can understand what I would like to do:
char configline[configmax_len + 1]; //configmax_len is the max value I need
while(fgets(configline, sizeof(configline), config){ //config is the file
char *configvalue = strtok(configline, " ");
if (configvalue[0] == "#"){
continue;
}
…
}
char * configvalue
is a pointer to the current line being read. What I would like to check is if the first character of the line is a "#".
However when I do the if statement: if (configvalue[0] == "#")
, the compiler throws an error: comparison between pointer and integer
.
How could I check if the first character of the string a pointer is pointing to is a certain value?
try using
if (configvalue[0] == '#'){
this should compile nicely
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With