c++二级指针的问题
.使用二级指针的方式输入三行文字,每行最多80个字符,分别统计出其中英文大写字母、小写字母、数字、空格以及其他字符的个数。并输出结果...
.使用二级指针的方式输入三行文字,每行最多80个字符,分别统计出其中英文大写字母、小写字母、数字、空格以及其他字符的个数。并输出结果
展开
3个回答
展开全部
#include <stdio.h>
#include <stdlib.h>
#define CNT 3
#define STR_LEN 80
#define IS_UP(ch) (('A' <= ch) && (ch <= 'Z'))
#define IS_LOW(ch) (('a' <= ch) && (ch <= 'z'))
#define IS_NUM(ch) (('0' <= ch) && (ch <= '9'))
#define IS_BLK(ch) ((ch == ' ') || (ch == '\t'))
void main()
{
int i, j;
int up, low, num, blk, oth;
// 二级指针
char * ppstr[CNT] = {NULL, NULL, NULL};
for (i = 0; i < CNT; i++)
{
// 动态内存分配80个字符的空间
ppstr[i] = (char *) malloc(sizeof(char) * STR_LEN);
if (ppstr[i] == NULL)
{
exit(1);
}
printf("请输入第%d个字符串:", i + 1);
gets(ppstr[i]);
}
for (i = 0; i < CNT; i++)
{
j = up = low = num = blk = oth = 0;
while (ppstr[i][j] != '\0')
{
char ch = ppstr[i][j];
if (IS_UP(ch))
{
up++;
}
else if (IS_LOW(ch))
{
low++;
}
else if (IS_NUM(ch))
{
num++;
}
else if (IS_BLK(ch))
{
blk++;
}
else
{
oth++;
}
j++;
}
printf("字符串\"%s\"共有%d个大写字母、%d个小写字母、%d个数字、%d个空格与%d个其他字符!\n",
ppstr[i], up, low, num, blk, oth);
// 释放分配的资源
free(ppstr[i]);
ppstr[i] = NULL;
}
}
#include <stdlib.h>
#define CNT 3
#define STR_LEN 80
#define IS_UP(ch) (('A' <= ch) && (ch <= 'Z'))
#define IS_LOW(ch) (('a' <= ch) && (ch <= 'z'))
#define IS_NUM(ch) (('0' <= ch) && (ch <= '9'))
#define IS_BLK(ch) ((ch == ' ') || (ch == '\t'))
void main()
{
int i, j;
int up, low, num, blk, oth;
// 二级指针
char * ppstr[CNT] = {NULL, NULL, NULL};
for (i = 0; i < CNT; i++)
{
// 动态内存分配80个字符的空间
ppstr[i] = (char *) malloc(sizeof(char) * STR_LEN);
if (ppstr[i] == NULL)
{
exit(1);
}
printf("请输入第%d个字符串:", i + 1);
gets(ppstr[i]);
}
for (i = 0; i < CNT; i++)
{
j = up = low = num = blk = oth = 0;
while (ppstr[i][j] != '\0')
{
char ch = ppstr[i][j];
if (IS_UP(ch))
{
up++;
}
else if (IS_LOW(ch))
{
low++;
}
else if (IS_NUM(ch))
{
num++;
}
else if (IS_BLK(ch))
{
blk++;
}
else
{
oth++;
}
j++;
}
printf("字符串\"%s\"共有%d个大写字母、%d个小写字母、%d个数字、%d个空格与%d个其他字符!\n",
ppstr[i], up, low, num, blk, oth);
// 释放分配的资源
free(ppstr[i]);
ppstr[i] = NULL;
}
}
展开全部
#define CNT 3
#define STR_LEN 80
#define IS_UP(ch) (('A' <= ch) && (ch <= 'Z'))
#define IS_LOW(ch) (('a' <= ch) && (ch <= 'z'))
#define IS_NUM(ch) (('0' <= ch) && (ch <= '9'))
#define IS_BLK(ch) ((ch == ' ') || (ch == '\t'))
void main()
{
int i, j;
int up, low, num, blk, oth;
// 二级指针
char * ppstr[CNT] = {NULL, NULL, NULL};
for (i = 0; i < CNT; i++)
{
// 动态内存分配80个字符的空间
ppstr[i] = (char *) malloc(sizeof(char) * STR_LEN);
if (ppstr[i] == NULL)
{
exit(1);
}
printf("请输入第%d个字符串:", i + 1);
gets(ppstr[i]);
}
for (i = 0; i < CNT; i++)
{
j = up = low = num = blk = oth = 0;
while (ppstr[i][j] != '\0')
{
char ch = ppstr[i][j];
if (IS_UP(ch))
{
up++;
}
else if (IS_LOW(ch))
{
low++;
}
else if (IS_NUM(ch))
{
num++;
}
else if (IS_BLK(ch))
{
blk++;
}
else
{
oth++;
}
j++;
}
printf("字符串\"%s\"共有%d个大写字母、%d个小写字母、%d个数字、%d个空格与%d个其他字符!\n",
ppstr[i], up, low, num, blk, oth);
// 释放分配的资源
free(ppstr[i]);
ppstr[i] = NULL;
}
}
#define STR_LEN 80
#define IS_UP(ch) (('A' <= ch) && (ch <= 'Z'))
#define IS_LOW(ch) (('a' <= ch) && (ch <= 'z'))
#define IS_NUM(ch) (('0' <= ch) && (ch <= '9'))
#define IS_BLK(ch) ((ch == ' ') || (ch == '\t'))
void main()
{
int i, j;
int up, low, num, blk, oth;
// 二级指针
char * ppstr[CNT] = {NULL, NULL, NULL};
for (i = 0; i < CNT; i++)
{
// 动态内存分配80个字符的空间
ppstr[i] = (char *) malloc(sizeof(char) * STR_LEN);
if (ppstr[i] == NULL)
{
exit(1);
}
printf("请输入第%d个字符串:", i + 1);
gets(ppstr[i]);
}
for (i = 0; i < CNT; i++)
{
j = up = low = num = blk = oth = 0;
while (ppstr[i][j] != '\0')
{
char ch = ppstr[i][j];
if (IS_UP(ch))
{
up++;
}
else if (IS_LOW(ch))
{
low++;
}
else if (IS_NUM(ch))
{
num++;
}
else if (IS_BLK(ch))
{
blk++;
}
else
{
oth++;
}
j++;
}
printf("字符串\"%s\"共有%d个大写字母、%d个小写字母、%d个数字、%d个空格与%d个其他字符!\n",
ppstr[i], up, low, num, blk, oth);
// 释放分配的资源
free(ppstr[i]);
ppstr[i] = NULL;
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
晕,这是C++吗,这明明是C行不?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询