How To Add Char Arrays In C
-
03-16-2019 #i
Registered User
How to add together a char assortment to an existing array of char arrays?
Lamentable the title sounds like a natural language twister. If I have an array of arrays similar so:
Code:
char *specials[24] = { "and", "or", "not", "equal", "plus", "minus", "times", "slash", "dollar", "percent", "at", "nothing", "one", "ii", "three", "four", "five", "six", "seven", "eight", "nine", "to", "for", "ate" };
Edit:
I added a function similar this:
Code:
void append_word(char **wordarray, int length) { wordarray[0] = "new_word"; }
Whatever aid would exist profoundly appreciated. Thank y'all.
Last edited by StruggleBot; 03-16-2019 at 03:52 PM.
-
03-xvi-2019 #2
TEIAM - problem solved
The normal way would exist to create "specials" using malloc()
You would so resize your original retentivity allocation using realloc()
Fact - Beethoven wrote his first symphony in C
-
03-17-2019 #3
C++ Witch
Since specials is an array of string literals, you should have declared information technology as:
Code:
const char *specials[] = { "and", "or", "not", "equal", "plus", "minus", "times", "slash", "dollar", "percent", "at", "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "ix", "to", "for", "ate" };
Code:
const char *specials[100] = { "and", "or", "not", "equal", "plus", "minus", "times", "slash", "dollar", "per centum", "at", "nix", "one", "two", "three", "four", "5", "six", "seven", "8", "ix", "to", "for", "ate" }; int append_word(const char **words, size_t size, const char *word) { size_t i = 0; while (i < size && words[i]) { ++i; } if (i < size) { words[i] = word; return ane; } else { return 0; } }
Code:
if (append_word(specials, 100, "new_word")) { // etc } else { // report/log fault concerning the specials assortment being full }
Originally Posted past Bjarne Stroustrup (2000-10-fourteen)
Look up a C++ Reference and learn How To Inquire Questions The Smart Way
-
03-17-2019 #iv
Registered User
Ah that's pretty neat... cheers
How To Add Char Arrays In C,
Source: https://cboard.cprogramming.com/c-programming/177229-how-add-char-array-existing-array-char-arrays.html
Posted by: halcombpuffined.blogspot.com
0 Response to "How To Add Char Arrays In C"
Post a Comment