Visibility of conversion void* in char* using malloc



  • For some reason, I'll catch a mistake in the conversion void* in char* using the malloc function.

    char *strLine = (char *)malloc(256);
    strLine = memset(strLine, 0x00, 256);
    

    The mistake is in the second line. The compiler tells me, mil, esteemed user, you mislead the variable strLine. Google, I found a very similar problem, too. mallocbut it's all decided to add it to the **char * * * * * * * * * * * * **** ahead of the malloc. What's the matter? Why doesn't that help me?



  • Well, you have a problem in line two, not in line one: strLine Type char*memset returns void*

    You could rock the return. memset'The meaning of char*♪ But you don't really need it. Just write.

    memset(strLine, 0x00, 256);
    

    You've already allocated memory, nothing new. memset You won't be here.


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2