So, I'm pretty new to C++. I have a problem copying a c-style string into an empty array of c-style strings. Here is the relevant code:
The code compiles just fine, but it stops running when it hits the line with strcpy(). (If I comment that line out, it runs to the end)
I would try another method, but this is how the professor wants it to be done. Actually, he was using strcpy_s(), which is specific to Microsoft as I understand. I'm using Xcode, so that's not an option.
Are there any masters of C++ out there that can explain my error for me?
Code:
bool addToList(char ** list, int * counts, char * word, int numwords) {
bool found = false;
(...)
if (!found) {
cout << "NOT";
strcpy(list[numwords],word);
counts[numwords] = 1;
numwords++;
}
return true;
}
int main() {
char **list;
int *counts;
counts = new int[100];
list = new char*[100];
int numwords = 0; // number of words
(...)
char * word;
word = "asdf";
addToList(list, counts, word, numwords);
return 0;
}
The code compiles just fine, but it stops running when it hits the line with strcpy(). (If I comment that line out, it runs to the end)
I would try another method, but this is how the professor wants it to be done. Actually, he was using strcpy_s(), which is specific to Microsoft as I understand. I'm using Xcode, so that's not an option.
Are there any masters of C++ out there that can explain my error for me?