发布网友 发布时间:2024-10-24 15:14
共3个回答
热心网友 时间:2024-11-06 00:58
呵呵,如果空格和标点符号严格的话,倒是很简单,如果稍微有些不严格的话,就需要仔细研究了。
热心网友 时间:2024-11-06 00:59
#include<stdio.h>
#include<string.h>
void print(char *str)
{
char *p;
p=strtok(str," ");
while(p)
{
printf("%s,%d\n",p,strlen(p));
str=strtok(str," ");
p=strtok(str," ");
}
}
void main()
{
char buf[512];
print(gets(buf));
}
热心网友 时间:2024-11-06 00:53
//---------------------------------------------------------------------------
#include <stdio.h>
#include <string.h>
char * prtword(char *w)
{
scanf("%*[^a-zA-Z\n]%[a-zA-Z]%*[^a-zA-Z\n ]",w);
return w;
}
int len(const char *w)
{
return strlen(w);
}
int main(void)
{
char wd[30];
do
{
printf("%s",prtword(wd));
printf(":%d\n",len(wd));
}while (getchar()!='\n');
return 0;
}
//---------------------------------------------------------------------------