当前位置:首页 » 编程语言 » c语言中种类的英文怎么输入
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

c语言中种类的英文怎么输入

发布时间: 2022-05-14 07:32:25

c语言求救,如何输入一句英文啊,如图,我定义三个数组,输入完第一个字母,只要打空格,就把下一个单词

你用scanf读取输入,自然只能读取一个单词。用gets读取输入,能够读到换行符为止,并且把换行符丢弃。

② C语言中如何输入英文报错只能输入汉字

#include"stdio.h"
intmain(intargc,char*argv[]){
chara[100],t[3],i;
printf("请输入汉字(输入0结束)... ");
for(i=0;i<50;i+=2){
while(1){
if(scanf("%2s",t)==1&&(t[0]<0&&t[1]<0||t[0]=='0'))
break;
printf("输入错误,重新输入... ");
fflush(stdin);
}
if(t[0]!='0')
a[i]=t[0],a[i+1]=t[1],a[i+2]='';
else
break;
}
printf("%s ",a);
return0;
}

供参考……

③ C语言如何键入特定英文字母然后输出特定数字

用两个数组:一个存放特定的字母,另一个存放对应的数字
当输入字母的时候编立字符数组,如果找到了这个字母就输出对应下标的数字
char
str[]={a,b,c,d},c;int
number[]={254,987,265,782};
scanf("%c",&c);
for(i=0;i<4;i++)
if(str[i]==c)
printf("%d",number[i]);

④ C语言中怎么输入数字和字母

需要准备的材料分别有:电脑、C语言编译器。

1、首先,打开C语言编译器,新建一个初始.cpp文件,例如:test.cpp。

⑤ c语言如何输入一些英文单词,然后只输出这些英文单词的大写后的首字母。

代码如下:


#include<stdio.h>
#include<stdlib.h>

intmain(intargc,char*args[])
{
charsentence[1024];

printf("sentence:");

gets(sentence);

char*p=sentence;

boolisWord=false;

while(*p!=''){

charch=*p;

if(ch>'A'&&ch<='Z'||
ch>='a'&&ch<='z'){

if(!isWord){

if(ch>='a'&&ch<='z')
ch-=32;

printf("%c",ch);

isWord=true;
}
}
else{
isWord=false;
}

p++;
}

printf(" ");

system("pause");
return0;
}

运行结果:

⑥ C语言:从键盘输入一篇英文文本,统计每个英文字母(分大小写)及空格、数字、回车和其他字符,咋编

程序代码:

#include <stdio.h>
#include <string.h>

#define MAX 10000

void input(char source[]);
void output(int sign[], int n);

void main()
{
char source[MAX];
int sign[256];
int i;

input(source);

for(i=0; i<256; i++)
{
sign[i] = 0;
}

//统计字符串中每个字符的数量
for(i=0; i<strlen(source); i++)
{
sign[source[i]]++;
}

output(sign, 256);
}

void input(char source[])
{
int i;

printf("input a string(end of EOF) : ");
for(i=0; i<MAX-1 && (source[i]=getchar())!=EOF; i++);
source[i] = '';
}

void output(int sign[], int n)
{
int i;

//输出数字
for(i='0'; i<'0'+10; i++)
{
printf("%c : %d ", (char) i, sign[i]);
}

//输出大写字母
for(i='A'; i<'A'+26; i++)
{
printf("%c : %d ", (char) i, sign[i]);
}

//输出小写字母
for(i='a'; i<'a'+26; i++)
{
printf("%c : %d ", (char) i, sign[i]);
}

//输出空格
i = 32;
printf("Space : %d ", sign[i]);

//输出回车
i = 10;
printf("Enter : %d ", sign[i]);

//输出其他字符
for(i=0; i<256; i++)
{
if(!(i>='0' && i<='9') && !(i>='A' && i<='Z') && !(i>='a' && i<='z') && i!=32 && i!=13)
{
printf("%c : %d ", (char) i, sign[i]);
}
}
}


运行测试:

⑦ C语言编程:从键盘中输入一个英文字符串

#include<stdio.h>

#include<stdlib.h>


int main()

{

int strSize = 100;

char *str = (char *)malloc(sizeof(char) * strSize);

int charNum = 0;

char input;

//逐个字符输入字符串,可以输入int可以表示的最大值个字符

printf("请输入任意个字符: ");

while(true)

{

scanf("%c",&input);

if(input != '#')

{

if((input >= 'A' && input <= 'Z') || (input >= 'a' && input <= 'z'))

{

if(charNum > strSize)

{

strSize += 100;

str = (char *)realloc(str,strSize);

}

str[charNum] = input;

charNum++;

}

}

else

{

break;

}

}

//输入结果分析

int i = 0,j = 0;

char *tempChar = (char *)malloc(sizeof(char) * charNum);

int *tempCharNum = (int *)malloc(sizeof(int) * charNum);

int charType = 0;

bool exist = false;

for(i = 0; i < charNum; i++)

{

exist = false;

tempChar[i] = '#';

tempCharNum[i] = 0;

for(j = 0; j < charNum; j++)

{

if(tempChar[j] == '#')

{

break;

}

if(tempChar[j] == str[i])

{

exist = true;

tempCharNum[j] += 1;

}

}

if(exist == false)

{

tempChar[charType] = str[i];

tempCharNum[charType] = 1;

charType++;

}

}

int t1;

char t2;

for(j = 0; j < charType - 1; j++)

{

for(i = 0; i < charType; i++)


if(tempCharNum[i] > tempCharNum[i+1])//如果a[i]大于a[i+1]

{

//交换a[i]和a[i+1]的值,即把较大的元素往后排

t1 = tempCharNum[i];

tempCharNum[i] = tempCharNum[i+1];

tempCharNum[i+1] = t1;


t2 = tempChar[i];

tempChar[i] = tempChar[i+1];

tempChar[i+1] = t2;

}

}

for(i = 0; i < charNum; i++)

{

if(tempChar[i] != '#')

{

printf("单词:%c,次数:%d ",tempChar[i],tempCharNum[i]);

}

}

free(str);

free(tempChar);

free(tempCharNum);

return 0;

}


⑧ C语言输入英文字母

cin>>ch;
if(ch=='a') cout<<'b';

输入输出形式换一下不就得了

⑨ c语言中,如何输入任意一串英文字母,然后按字母相反顺序输出这一串字母

#include <string.h>
#include <stdio.h>
int main(void)
{
char ch[100];/*假设字符串最长100个字符*/
printf("请输入字符串\n");
gets(ch);//可以实现输入空格
int len= strlen(ch);/*求字符串长度*/
for (int i=len;i>=0;i--)
printf("%c", ch[i]);
printf("\n");
}