0

This question took me long enough to figure out that I figured I would ask and answer in case some future student had the same problem. I actually had the same problem in Psets 1 and 2, but I took a month off between them and forgot again!

The expected behavior: The program will index into the input array and compare the value at that index to a space character. If the two are equivalent (ie, the character in the string at that index is a space), it will execute the code in curly brackets.

The code:

if (input[i] == " "){
//do stuff
}

The compiler error:

error: incompatible integer to pointer conversion passing 'char' to parameter of type 'const char *'; take the address with & [-Werror,-Wint-conversion]

So I tried using &, and got a new error, and eventually it suggested I use "strcomp", so I looked at the man page for strcomp, and implemented the code in a new way, checking for the output of strcomp(input[i]," ") to equal 0... but still got the same error in the end.

2

It turns out that using double quotes vs single quotes makes a difference in C!

Double quotes are used to wrap a STRING, while single quotes are used to wrap a CHARACTER. This is easy to remember if you just think about single quote, single char.

Replacing

if (input[i] == " "){

with

if (input[i] == ' '){

Fixed the problem.

reference: https://stackoverflow.com/questions/3683602/single-quotes-vs-double-quotes-in-c

| improve this answer | |

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .