-4
我正在写下面的代码来处理字符串的长度的基础上,但我得到了分段错误,搜索它并发现它与指针有关,但无法找出原因对于相同的。无法找到分割故障的原因
#include <string.h>
#include <iostream.h>
#include <stdio.h>
int main()
{
char input[500];
strcpy(input, "quick brown fox jumps on lazy dog");
const char s[2] = " ";
unsigned int num = 7;
unsigned int lent;
cin >> num;
char *token;
token = strtok(input, s);
while(token != NULL)
{
lent= strlen(token);
if(lent <= num)
printf(" %s", token);
token = strtok(NULL, s);
if(strlen(token) <= (num-lent))
printf("%s",token);
printf("\n");
}
return(0);
}
您是否尝试过使用调试器? –
这是您学习'gdb'的好时机。 – Shravan40
我无法得到您的观点 – OshoParth