#include <stdio.h>
#include <string.h>
const int MAX=256;
//应用指针统计一个字符串中有多少个单词
int main() //不留空 填void
{
char* nums[]={ "one" , "two" , "tree" , "four" , "five"\
, "six" , "seven" , "eight" , "nine" , "ten" };
char word[MAX]={'\0'};
char* test="This is a test number of words in the sentences."; //貌似英文是病句
char* p1=test;
char* p2=test;
int len=0;
int index=0;
while(1)
{
if (*(p2+1)!=0x20)
{
p2++;
if (*p2!='\0') continue;
}
p2++;
len=(int)(p2-p1);
strncpy(word,p1,len);
word[len]='\0';
printf("the %5s word is : %s\n",nums[index],word); //第几个 应该是1st 2nd 3nd 4nd 这样的
p2++;
p1=p2;
index++;
if (*p2=='\0') break;
}
return 0;
}
/*
样例输出:
the one word is : This
the two word is : is
the tree word is : a
the four word is : test
the five word is : number
the six word is : of
the seven word is : words
the eight word is : in
the nine word is : the
the ten word is : sentences.
*/
我这几个值多少分?
#include <string.h>
const int MAX=256;
//应用指针统计一个字符串中有多少个单词
int main() //不留空 填void
{
char* nums[]={ "one" , "two" , "tree" , "four" , "five"\
, "six" , "seven" , "eight" , "nine" , "ten" };
char word[MAX]={'\0'};
char* test="This is a test number of words in the sentences."; //貌似英文是病句
char* p1=test;
char* p2=test;
int len=0;
int index=0;
while(1)
{
if (*(p2+1)!=0x20)
{
p2++;
if (*p2!='\0') continue;
}
p2++;
len=(int)(p2-p1);
strncpy(word,p1,len);
word[len]='\0';
printf("the %5s word is : %s\n",nums[index],word); //第几个 应该是1st 2nd 3nd 4nd 这样的
p2++;
p1=p2;
index++;
if (*p2=='\0') break;
}
return 0;
}
/*
样例输出:
the one word is : This
the two word is : is
the tree word is : a
the four word is : test
the five word is : number
the six word is : of
the seven word is : words
the eight word is : in
the nine word is : the
the ten word is : sentences.
*/
我这几个值多少分?