Search Results

Search found 1 results on 1 pages for 'ostap hnatyuk'.

Page 1/1 | 1 

  • C appending char to char*

    - by Ostap Hnatyuk
    So I'm trying to append a char to a char*. For example I have char *word = " "; I also have char ch = 'x'; I do append(word, ch); Using this method.. void append(char* s, char c) { int len = strlen(s); s[len] = c; s[len+1] = '\0'; } It gives me a segmentation fault, and I understand why I suppose. Because s[len] is out of bounds. How do I make it so it works? I need to clear the char* a lot as well, if I were to use something like char word[500]; How would I clear that once it has some characters appended to it? Would the strlen of it always be 500? Thanks in advance.

    Read the article

1