incompatible pointer to integer conversion

link to my file https://ide.cs50.io/rahulatrkm/ide50#openfile-x

I was geeting message like this

clang -fsanitize=integer -fsanitize=undefined -ggdb3 -O0 -std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wshadow    initials.c  -lcrypt -lcs50 -lm -o initials
initials.c:7:9: error: incompatible pointer to integer conversion initializing 'int' with an expression of type 'string' (aka 'char *')
    int name = get_string();
        ^      ~~~~~~~~~~~~
initials.c:8:21: error: subscripted value is not an array, pointer, or vector
2 errors generated.
make: *** [initials] Error 1

The problem is your declaration of name as an int. get_string tries to return a string (or char array). It can't store the string ( a char array )in an int. The second error is similar. Since name is an int, it cannot be treated as an array.

Correct the var type of name and it should work.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

  • You wouldn't declare name as an array of char (and especially not as a "string array" as you wrote), but as a pointer to char, maybe aliased as string (declared in cs50.h as being char*). – Blauelf Feb 27 '17 at 10:38
  • I was trying not to give away the actual solution, so that Rahul could figure it out, but the following would work just fine: string name = get_string(); At this point, keep it simple. ;-) But you were right that it should not be a "string array", i.e., an array of strings. I have corrected that. thanks. – Cliff B Feb 27 '17 at 11:03

You must log in to answer this question.

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