I'm trying to use strncpy_s to characters from one word to an array (I cannot use strncpy in Visual Studio 2013 and I'm totally new to strncpy_s). I keep getting these errors whatever I do:
Error 1 error C2660: 'strncpy_s' : function does not take 3 arguments
Error 2 IntelliSense: no instance of overloaded function "strncpy_s" matches the argument list argument types are: (char *, char, int)
The purpose of my code is:
If user inputs, for example, "HELLO" (that is, text = HELLO) Then ->
Copy HELLO to first_array [0] Copy ELLO to first_array [1] Copy LLO to first_array [2] Copy LO to first_array [3] Copy O to first_array [4]
And here's my code:
int _tmain(int argc, _TCHAR* argv[])
{
char text[32];
cin >> text;
char* first_array[] = {""};
int n = strlen(text);
for (int i = 0; i < n; i++)
{
strncpy_s(first_array[i], text[i], n-i);
}
}
EDIT 1. Modified the code a bit more, now the program runs, but after inputing a text, it suddenly gives me the "example.exe stopped working" error.
int _tmain(int argc, _TCHAR* argv[])
{
char* text[32];
cin >> *text;
char* first_array[] = {""};
//int n = strlen(text);
int n = sizeof(text);
for (int i = 0; i < n; i++)
{
strncpy_s(first_array[i], n - i, text[i], 32);
}