Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

First character of pointer

Tags:

c

char

pointers

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?

like image 968
Dezzy Avatar asked Dec 15 '22 04:12

Dezzy


1 Answers

try using

if (configvalue[0] == '#'){

this should compile nicely

like image 59
Tom Avatar answered Dec 29 '22 11:12

Tom