주어진 char (이 경우 pe pees whitespece)의 구성 요소를 인쇄해야하는데 왜 이것이 작동하지 않는지 이해하지 못합니다 (컴파일하지 않습니다) : (또는 여기 http://ideone.com/JSrqg5).Strcpy 및 strtok이 작동하지 않습니다.
오류는 다음과 같습니다
error C4996: 'strtok': This function or variable may be unsafe. Consider using strtok_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. c:\users\ellly\documents\visual studio 2013\projects\consoleapplication15446\consoleapplication15446\source.cpp 18 1 ConsoleApplication15446
error C2664: 'char *strcpy(char *,const char *)' : cannot convert argument 1 from 'char' to 'char *' c:\users\ellly\documents\visual studio 2013\projects\consoleapplication15446\consoleapplication15446\source.cpp 21 1 ConsoleApplication15446
그리고 코드 :
#include <iostream>
#include <cstring>
using namespace std;
char s[20000], *p, a[5000], separator[] = " ";
int k = 0, i;
void separare();
void afisare();
int main()
{
cout << "Sirul de nr:"; cin.get(s, 100, '\n');
separare();
afisare();
system("pause");
return 0;
}
void separare()
{
p = strtok(s, separator);
while (p)
{
strcpy(a[k], p);
k++;
p = strtok(NULL, separator);
}
}
void afisare()
{
int i;
for (i = 0; i < k; i++)
cout << a[i] << " ";
}
나는 cstring 라이브러리를 포함시켜야한다고 생각한다 : #include –
수정 한 후에는 strcpy와 strtok을 다시 가리킨다. – Daniq
당신이 말하는 "작동하지 않는"것은 무엇입니까? –