當前位置:首頁 » 編程語言 » 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");
}