This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

New array declaration

Hi everyone

can someone tell me how to declare a array of 20 characteres. I wanto to use this array to fill with a string and then display it in a LCD. Also I wanto to use a pointer to read or write in this array

thanks

Parents
  • but, if the length of the string which you declared is twenty,you don't need to specify the length,but while it is less than 20, for example

    char idata str[]="hello";
    
    however,you need to store a 20-length string later on, does's it work?
    eg.
    strcpy(str,"this a 20-char sting");
    

Reply
  • but, if the length of the string which you declared is twenty,you don't need to specify the length,but while it is less than 20, for example

    char idata str[]="hello";
    
    however,you need to store a 20-length string later on, does's it work?
    eg.
    strcpy(str,"this a 20-char sting");
    

Children
  • "you need to store a 20-length string later on"

    that's why I said, "...unless you have a specific reason to do so..."

    In that case, yes - you would need to explicitly state the length as 21 in the definition.

    strcpy(str,"this a 20-char sting");
    The 1st parameter to strcpy just tells it where to start copying to; see strncpy if you want to limit the maximum number of characters to copy!