用C语言求一个字符串长度,要求长度小于20,否则要重新输入

[复制链接]
查看11 | 回复3 | 2011-7-1 15:00:14 | 显示全部楼层 |阅读模式
楼下的写的不对..没达到要求....

回复

使用道具 举报

千问 | 2011-7-1 15:00:14 | 显示全部楼层
#include#includeint main(void){char s[50];printf("请输入一个字符串:");scanf("%s",s);while(strlen(s)>=20){printf("字符串长度大于20,请重新输入:");scanf("%s",s);}printf("\n字符串的长度是:%d\n",strlen(s));return 0;}...
回复

使用道具 举报

千问 | 2011-7-1 15:00:14 | 显示全部楼层
#include int main(void){char szStr[64] = {0};while(1){scanf(" %s", szStr);if (strlen(szStr) void main(){int i;loop :printf("please input string :");for(i = 0; getchar()!='\n'; i++);if(i >= 20) {printf("over 20\n");goto ...
回复

使用道具 举报

千问 | 2011-7-1 15:00:14 | 显示全部楼层
用库函数,strlen...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行