#define STDC_WANT_LIB_EXT1 1
#include
#include
#include
int main(void)
{
char delimiters[] = " \".,:;!?)(";
char buf[100];
char str[1000];
char * ptr = NULL;
str[0] = '\0';
size_t str_len = sizeof(str);
size_t buf_len = sizeof(buf);
printf("Enter some prose that is less than %zd charaters.\n"
"terminate input by entering an empty line:\n",str_len);
while(true)
{
if(!gets_s(buf, buf_len))
{
printf("Error reading string.\n");
return 1;
}
if(!strnlen_s(buf, buf_len))
break;
if(strcat_s(str, str_len, buf))
{
printf("Maximum permitted input length exceeded.\n");
return 1;
}
}
printf("The words in the prose that you entered are:\n",str);
unsigned int word_count = 0;
char * pWord = strtok_s(str, &str_len, delimiters, &ptr);
if(pWord)
{
do
{
printf("%-18s",pWord);
if(++word_count % 5 ==0)
printf("\n");
pWord = strtok_s(NULL, &str_len, delimiters, &ptr);
}while(pWord);
printf("\n%u words found.\n", word_count);
}else
printf("No word found.\n");
return 0;
}
问题1: str[100]和buf[1000]是什么?
问题2: str[0] = '\0';是什么意思?
问题3: while循环在干什么?
问题4:strtok_s()工作流程?
望各位大神指教!