-6

i got 2 error messages for the code, I tried to figure it out myself searching online but it didn´t help. the message are like this:

error: incompatible integer to pointer conversion passing 'char' to parameter of type 'const char *'; take the address with & [-Werror,-Wint-conversion] strcpy(genHash,crypt( letters[i], "abc"));

the other one is the same message but for passW[0]. I just want to understand what happen. I would appreciate any help. Also if anyone can recommend a good lecture about char arrays, char arrays using pointers. thanks

Barmar
  • 741,623
  • 53
  • 500
  • 612
Luis
  • 1
  • 1
  • 1
    Downvote: It is quite hard for us to identify the source of the error. It is also disruptive to turn an entire paragraph as a link. Instead, post the source code as text, and you can also provide a link to the photo your current link posts to. – Ṃųỻịgǻňạcểơửṩ May 10 '18 at 23:11
  • The error means that you've tried to pass a single character where the function expects a string (an array of multiple characters). Do you know the difference between characters and strings in C? – Steve Summit May 10 '18 at 23:14
  • Hi, try to read some other questions to check some examples on how to ask a question. In this form this question is likely to be closed soon. – Stefan May 10 '18 at 23:15
  • Welcome to Stack Overflow! Post your code as plain text, not an image. See https://stackoverflow.com/help/formatting for code formatting help. – Barmar May 10 '18 at 23:54

2 Answers2

0

When you call a function and pass letters[i] or passW[0], you are passing a single character. But it sounds like these functions expect entire strings, that is, arrays of characters.

You might be able to get away with passing letters instead of letters[I], and passW instead of passW[0]. (But it's hard to be sure, because you haven't shown us your code.)

Steve Summit
  • 45,437
  • 7
  • 70
  • 103
0

If you want to learn about char arrays and char array pointers then you should grab a copy of 'The C programming language' by Kernighan and Richie. It has a whole chapter on it. It's also a spectacular reference for C in general.

Char variables are actually unsigned 8-bit (1 byte) integers in C/C++. They have values from 0 to 255. When you use fputs() or other print functions in C/C++, these integer values are converted to characters based on your chosen character/type set.

Have you checked the type of the output that crypt() returns? If you're using a genuine GNU compiler then you can use the typeof() function/operator to check the output. Or you could look for the definition of crypt() in your header files. It's possible that it isn't the input to crypt that's causing the problem. It could be nesting crypt() inside strcpy() without an appropriate cast.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Russell Jurek
  • 84
  • 1
  • 1
  • 7
  • Thanks a lot! this is helpful. Both observations give new points where start working to fix this. thanks. – Luis May 11 '18 at 16:59