C语言:(用指针编写)输入一行文字,找出其中大写字母,小写字母,空格,数字以及其他字符各有多少?

作者&投稿:莱牲 (若有异议请与网页底部的电邮联系)
c语言用指针编写,输入一行文字,找出其中大写字母,小写字母,空格,数字以及其他字符各有多少?~

#include
void main()
{
int a=0,b=0,c=0,d=0,e=0,i=0;
char *p,s[20];
while((s[i]=getchar())!='
')i++;
p=s;
while(*p!=10)
{
if(*p>='A'&&*p<='Z')
a++;
else if(*p>='a'&&*p<='z')
b++;
else if(*p==' ')
c++;
else if(*p>='0'&&*p<='9')
d++;
else e++;
p++;
}
printf("大写字母 %d 小写字母 %d
",a,b);
printf("空格 %d 数字 %d 非字符 %d
",c,d,e);
}

#include
#include
#include
using namespace std;

int main()
{
char s[80];
gets(s);

int upper,lower,number,space,other;
upper=lower=number=space=other=0;
char *p;
for(p=s;*p;p++)
{
if(isupper(*p)) upper++;
else if(islower(*p)) lower++;
else if(isdigit(*p)) number++;
else if(isspace(*p)) space++;
else other++;
}

cout<<"大写字母有"<<upper<<"个"<<endl;
cout<<"小写字母有"<<lower<<"个"<<endl;
cout<<"数字有"<<number<<"个"<<endl;
cout<<"空格有"<<space<<"个"<<endl;
cout<<"其他有"<<other<<"个"<<endl;

return 0;
}

if(*p++>='A'&&*p++<='Z')
a++;
算法有问题,
你判断的时候,不管是否符合,都++运算了,而且可能还连加两次,那当前字符就不管它了么


C语言利用指针编写函数,输入3个学生2门课成绩,计算每个学生的平均分和...
给你一个简单的程序。 希望能看的懂。include "stdafx.h"include "stdio.h"int main(int argc, char* argv[]){ int a,b,c;printf("a学生成绩是:");int a1,a2;scanf("%f,%f",&a1, &a2);printf ("b学生成绩是:");int b1,b2;scanf ("%d,%d",&b1,&b2);int c1,c2;printf("...

C语言编程用指针编写函数,将一个二进制数(以字符串形式表示)转换为十...
double binTodec(char *str){ int i = 0, j; double p1 = 1, p2 = 0.5; double res = 0; while(str[i]!='\\0' && str[i]!='.') j = i++; do{ res += (str[j--]-'0')*p1; \/\/ 计算整数 p1 *= 2; }while(j >= 0); i...

C语言使用指针输出字符
include <stdio.h>int main(){ char name[5][10]={"赵XX","钱XX","孙XX","李XX","周XX"}; char *p[5] ; int i; for(i = 0; i < 5; i++) { p[i] = name[i]; } for(i = 0; i < 5; i++) { printf("%s\\n",p[i]); }...

...编写求其最大值、最小值的函数,用指针作函数参数实现。
程序如下:#include<stdio.h>#define MAXSIZE 10main(){int a[MAXSIZE];int k;printf("please inter ten number:");for(k=0;k<MAXSIZE;k++){ scanf("%d",&a[k]);} Fun(a);for(k=0;k<MAXSIZE;k++)printf("%d,",a[k]);} void Fun(int a[]){ int i;int temp;int Max...

...统计其中的数字与字母个数并输出。(用指针实现)
include<stdio.h> int j=0,k=0,l=0;int main(){char a[100],*p;void can(char *p);printf("输入一个字符串");p=a;gets(a);can(p);printf("大写字母%d个\\n",j);printf("小写字母%d个\\n",k);printf("数字%d个\\n",l);return 0;} void can(char *p){for(;*p;p++)if((...

C语言用指针输出第几到第几个字符?
1. 可以 char s[] = "123456";char *p = s;int i;for(i = 4; i <=6; i++) printf("%c", *(p+i - 1));2. 也可以 char s[] = "12345";char *p = s +1;int N=2;int i;for(i = 0; i < N; i++) printf("%c", *(p + i));不用for循环,c语言默认没...

C语言实验六实验报告——指针
 2.编程实现:将一个任意整数插入到一个已排序的整数数组中,插入后数组中的数仍然保持有序。要求:(1)整数数组由初始化方式输入。任意整数由scanf函数输入;(2)实现过程采用指针处理;(3)输出原始数组数据以及插入数据后的数组数据并加以相应说明。3.编写函数newcopy(char*new,char*old...

C语言:编写函数,用指针型形参访问数组,把给定数组转置,并给出运行截...
由于题目没有说明数组是方阵,所以本答案按一般二维数组处理。代码文本:include "stdio.h"define N 3 define M 5 void myf(int a[][M],int b[][N],int i,int j){\/\/本函数将数组a转置为b int t;for(t=j-1,i--;i>=0;i--)for(j=t;j>=0;b[j][i]=a[i][j--]);} int...

C语言:利用函数指针编写一个用矩形法求定积分的通用函数,包括正弦,余弦...
for(i=0;i<n;i++)这里用i<=n的话会多计算一个区间

C语言 用指针编写在数组中查找指定值指针的函数
不用万分感谢,只要十分感谢即可。 对于函数:int* find(int a[], int value),其中a为整型数组首地址,value是被检验值。我们可以利用指针a间接引用数组第一个元素的值,并将其与value比较,比较完后,将指针向后移动,再通过间接引用的方式比较下一个元素值,依次下去,直到在整型数组中找到被检验值或者整型数组所有元...

桥西区15572348482: c语言用指针编写程序:输入一行字符,将其中的字符从小到大排列后输出. -
达常瑞菲: //用的是qsort快排.#include#include#include int comp(void const *a,void const*b) { return *(char*)a-*(char*)b; } int main() { char str[100]; gets(str); qsort(str,strlen(str),sizeof(str[0]),comp); puts(str); }

桥西区15572348482: c语言 用指针方法处理:输入一行字符,统计并输出其中大写字母、小写字母、空格、数字及其它字符的个数. -
达常瑞菲: #include<stdio.h> void main() { int a=0,b=0,c=0,d=0,e=0,i=0; char *p,s[20]; while((s[i]=getchar())!='\n')i++; p=s; while(*p!=10) { if(*p>='A'&&*p<='Z') a++; else if(*p>='a'&&*p<='z') b++; else if(*p==' ') c++; else if(*p>='0'&&*p<='9') d++; else e++; p++; } ...

桥西区15572348482: 用C语言写程序:从键盘输入一行文字,统计出该行字符中大写字母,小写字母,空格等的个数.要求用到指针. -
达常瑞菲: char c[80],m; gets(c); int *p; int num=0,i; p=&num; for(i=0;(m=c[i])!=0;i++) {if(c[i]>='A'&&c[i]<='Z') num++;} 这个只能统计出 大写字母个数 楼主 看着在IF下边加两行就行了

桥西区15572348482: C语言用指针输入一串字符,并逆向输出. -
达常瑞菲: #include <stdio.h> void main(void) { unsigned char i = 0, j, temp1[200], temp2[200]; /*设定变量*/ printf("\n\n\n Please Input yuan_wenzi: "); /*提示输入*/ scanf("%s", temp1); /*输入字符串到TEMP1*/ while(temp1[i] != '\0') {temp2[i] = temp1...

桥西区15572348482: c语言输入一行文本输出一行文本 -
达常瑞菲: 比较简单的方法就是设个全局变量,参考代码如下: #include<stdio.h> char str[500]; char *GetText() {gets(str);return str; } int main() { puts(GetText()); return 0; }

桥西区15572348482: 编程输入一行字符,运用指针找出其中的大写字母,空格,数字,及其他字符的个数. 用C语言指针怎么写呢? -
达常瑞菲: #includevoid main() { char s[256],*p; int a,b,c,d; gets(s); p=s; a=b=c=d=0; while ( *p!=0 ) { if ( *p>='A' && *p<='Z' ) a++; else if ( *p==' ' ) b++; else if ( *p>='0' && *p<='9' ) c++; else d++; p++; } printf("大写字母%d,空格%d,数字%d,其他%d.\n",a,b,c,d); }

桥西区15572348482: 分别用C语言指针和函数:输入一行字符,分别统计出其中英文字母,空格,数字和其他字符的个数 -
达常瑞菲: #include<stdio.h> void main() { //char a[50]; int letter=0,number=0,blank=0,other=0; //int i; //gets(a); char c; 用来读取每个字符while ((c=getchar())!='\n') //基本就是修改的这句,当读入的是回车即为结束运算 //for(i=0;i<50,a[i]='\n';i++) { if((c>='a'&&...

桥西区15572348482: c语言指针 输入一行字符 判断是否对称 要求使用指针 -
达常瑞菲: //---------------------------------------------------------------------------#include <stdio.h> #include <string.h>int main(void) {char str[80],*p=str;int i;gets(str);for (i = 0; i<strlen(p)/2; i++) {if (*(p+i)!=*(p+strlen(p)-1-i)) {i=strlen(p);break;}}puts(i==strlen(p)?...

桥西区15572348482: c语言输入一串字符,输出字符长度用指针 -
达常瑞菲:#include #includeint length(const char*); int main() { char str1[100],*p; // 这里应是char型int a;p=str1;gets(str1);a=length(p);printf("%d\n",a);return 0; }int length(const char*s) // 此函数也作了修改 {int len=0;for(;*s!='\0';s++) len++;return(len); }

桥西区15572348482: c语言 指针输入 -
达常瑞菲: 你定义了一个指针s,却不让他指向什么,scanf("%d",s+i);当人会有问题#include int main() { int a,b,i; int *s; int p[8]; s = p; for(i=0;iscanf("%d",s+i); for(i=0,a=1;i{ a=i+1; for(;aif (*(s+i)} for(i=0;iprintf("%d",*(s+i)); return 0; } 指针一定要指向一个地址

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网