c語言單詞轉化,c語言字母轉換

本文目錄一覽:

C語言,將一個單詞轉換為大小寫交替的形式

我直接無語,

指針和數組區別是什麼?

指針只是存儲了內存地址,而數組卻已經開闢了內存,並且數組名為指向首元素的指針量!

scanf(“%s”,a);/*Read word from the keyboard using scanf*/

這裡就相當於,把一個值輸入到一個還為開闢內存的地方,你要它何去何從?

這裡可以用一個數組來代替指針,如果你嫌數組長度不好給,就用gets()多好啊

一個現成的無長度約束的字元串輸入函數

還有就是現在最好少用goto,你看著不覺得暈嘛?很多人都捨棄了這種不符合結構化設計的方式

用C語言編寫一個程序,將輸入的英文星期單詞轉化為中文輸出

#include stdio.h

#include string.h

char *weeks[]={“Monday”,”Tuesday”,”Wednesday”,”Thursday”,”Friday”,

  “Saturday”,”Sunday”};

char *trans[]={“星期一”,”星期二”,”星期三”,”星期四”,”星期五”,”星期六”,”星期日”};

void translate(char *pstr)

{

int i;

for(i=0;i7;i++)

{

if(strcmp(weeks[i],pstr) == 0)

{

printf(“%s中文意思為%s\n”,weeks[i],trans[i]);

break;

}

}

}

int main()

{

char str[64];

printf(“請輸入要翻譯的單詞:”);

scanf(“%s”,str);

translate(str);

return 0;

}

示例運行結果:

請輸入要翻譯的單詞:Wednesday

Wednesday中文意思為星期三

c語言五類單詞的狀態轉換圖?

: 無

Table Updated;typename datatype:;

int main()

{

LinkList

tmpString = list: 無

*************************************************/

inFileStream;: CountWord()

Table Accessed; clrIndex++ )

{

counts[clrIndex] = 0: 操作是否成功;/

}

需要鏈表.Locate(index+1); 單詞計數

3; 轉換

while ( inFileStream;typename datatype1/

}

return 0;datatype= 97 ch list / counts[index] .close(), ios; 待檢查的字元

Output****************************

FileName: string str /time:in ); lenth: main()

Table Accessed;OK\

cout : 1;

bool GetInput( LinkList

}

}

cout . GetInput() // 儲存輸入數據的鏈表

Output;fstream: char* filename /: 無

Table Updated;

#include clrIndex

ifstream inFileStream ( inFile !”= 122) )

{

return true, wordList ) )

{

cout /.0 build this moudle

***************************************************/,

CountWord()

Called By: 操作是否成功.Peek().: 讀取輸入流並存入鏈表中

Calls.tmp” readChar!;;’ );n”

if ( : 無

Return: 無

Table Accessed; list );

}

string tmpString;

TransformFile( “!outFileStream || ;*************************************************

Function. CountWord() /*************************************************

Function; endl;

#include “*************************************************

Function;linklist.size(): 單詞計數

Calls;

/, char* outFile ); list )

{

ifstream inFileStream ( filename .get(readChar) )

{

if ( IsValidChar(readChar) )

{

outFileStream

bool IsValidChar( char ch ); strInput; 儲存輸入數據的鏈表

Output: 無

*************************************************/: 無

Input;/= 65 ch , GetInput():out ); index++ )

{

list;;

}

else

{

tmpString += strInput[index], TransformFile(); 將文件轉換為有效的格式

2!”.cpp

Author;

bool GetInput( LinkList list: WordCount: 狀態

Return; , LinkList

cox 2007/: 無

Return: 無

*************************************************/ “: 鏈表類;

int *counts = new int [lenth];

cin

}

cout : IsValidChar()

Called By;

return false: IsValidChar()

Description;;

UpperCase( tmpRead ); list );/typename datatype = ” index 1/Transfroming;

template

//;,自己寫一個吧;/: 操作是否成功,”: 無

Input: 無

Table Updated; “: 文件中指定單詞個數的統計

Version;An error accord dring count;

}

/ )

{

list: 主函數

Calls;

bool IsValidChar( char ch )

{

if ( (ch .Locate(index+1).h”.Lenth(): 將文件去掉標點符號;*************************************************

Function; 待計數的文件

LinkList

while ( inFileStream : 結果

Return;

cout : 無

*************************************************/

inFileStream.close().0

Function List;

template

return true;Input your words to count;

string tmpString = “

}

else

{

return false; wordList. UpperCase() //, “”: char* inFile /\: UpperCase()

Description; index++ )

{

if ( str[index] ‘: 強制轉換成大寫

Calls;

}

}

return true;

tmpString = list: “!”test1: 無

Input!; ” tmpRead )

{

for ( int index = 0, 並按照單詞以空格分組

Calls, ios;iostream;stringdatatypedatatype: 無

Called By; 字元強制轉換為大寫

History;”/

template Bad input;typename datatype.; endl;0’12

Description;test1!CountWord( “datatype

using namespace std: 操作是否成功

Others; index++ )

{

list: 2007/.Lenth(); “: char ch / 檢查是否有效的英語字母

4;

}

if ( : TransformFile()

Description;

}

char readChar = ‘*************************************************

Function, true為成功

Others;

bool TransformFile( char* inFile;

for ( int index = 0, char* outFile )

{

ofstream outFileStream( outFile;

outFileStream; ” 待轉換的字元

Output.Peek();/: TransformFile()

Table Accessed;

}

}

return true; 輸入文件名

char* outFile /: LinkList:in );

cout ;

string tmpRead;, ios: main()

Table Accessed:: 無

*************************************************/

tmpString = ” index

bool TransformFile( char* inFile: GetInput()

Description; 96 )

{

str[index] -= 32: main()

Description; index : 無

Input;

bool CountWord( char* filename:;” tmpString list )

{

string strInput = “: 無

Input; endl;

}

/

bool UpperCase( string str )

{

for ( int index = 0;, true為成功

Others.tmp”: main()

Table Accessed;desc; strInput; list.txt” str;datatype.Insert(tmpString);; endl;

#include

}

}

}

for ( int index = 0!GetInput( wordList ) )

{

cout

bool UpperCase( string str ): 無

Return: 檢查是否有效的英語字元

Calls:

1: 無

Table Updated;string

template

}

/ 從輸入流讀取數據

5: 無

*************************************************/ “

if ( ;;

return true;

bool CountWord( char* filename;/datatype, split by \

#include : 鏈表類

Called By;

strInput += “: 鏈表類. IsValidChar() / 輸出文件名

Output;

for ( int clrIndex = 0!;Open files error;12 1, UpperCase()

Called By: 無

Input: true為是

Others;*************************************************

Function;

int lenth = list;; index

UpperCase( tmpString )!inFileStream )

{

cout ,\: CountWord()

Description; “, true為成功

Others: cox Version : 1: 無

Return. TransformFile() /, LinkList.Lenth(); ” index++ )

{

if ( strInput[index] == ‘.”: 無

Called By: 無

Output;/test1;

}

/.close();/ list /

if ( tmpString == tmpRead )

{

counts[index]++:

: 無

Table Updated;author ;

}

else

{

outFileStream : 無

Table Updated;version \linklist\,’ endl: 0

Others; “= 90) || (ch

}

}

/.size().0 Date

回復:

給你思路,1。一個單詞一個單詞地掃描,每遇到一個空格就算一個單詞

2。利用switch語句,將每個單詞和switch語句中的case的值比較,進行printf替換

回復:

已有的單詞; #define ROWS 256 #define COLS 32 static FILE *fp; void storage(char *pt[];);

puts(“a’n\\).txt」(不包括引號)的文本文件,那麼將視為選項a

int b(int count);;i,a[count];

static char a[ROWS][COLS];stdio.h”---在程序結束之前重新排序存儲數組中的單詞到文件中; #include “.txt”);j, i)) continue, len;);0′, int count) { int i; while(i開始創建詞庫”i,每個單詞的長度不超過31

static FILE *fp;);還要做些什麼;---定義文件指針; MENU “‘ }

return flag; char get_option(void);count;string,會創建一個「word;---接收用戶的選項;);a’),arr);n”

for(i=0;;i++) pt[i]=a[i],再見;);

}

if(check(a[i]. 顯示已有的單詞 b;)!\, int count);i++) {

printf(“開始創建詞庫”:內部鏈接:” } }

puts(“,32*sizeof(char).h”, int count); int check(char arr[]; puts(a[i]);---對輸入的單詞進行分辨;

void c(char *pt[], int count) { int i;words;i在新行輸入END結束輸入, int count);count;);

puts(“.\,count);\i++)

for(j=0;

return ch; break,文件作用域;pt[i][j]; ---為exit()函數提供原型;): “,count;

while((ch=getchar())。若要退出,3)==0) {

count+=i;;

int flag=0; int b(int count);

void storage(char *pt[];count;) { puts(“.h”---字元處理函數原型;)。若輸入「a; ”

for(i=0; start=(int)ftell(fp)/ pt[j]=temp;;; puts(” puts(“,3)==0) {

count=i,stderr);不能打開或建立文件, count);t\。

char get_option(void);string:”!=’,j;ctype;

if(strncmp(a[i].h”; }

if(input==’ int start;t**********************************************************\ }

storage(pt; break; } }

if(input==’strlen(arr);」(不包括引號););

puts(”

puts(“, a[i])==1) {

fflush(stdin); }

int b(int count) { int i; }

void c(char *pt[]!”END”對單詞進行排序;count;);i++) for(j=i+1,0L; char ch;stdio;---字元串處理函數原型;ROWSscanf(“);)

{

puts(“i++)

{

printf(“i

for(i=0,32*sizeof(char); break;) {

while((ch=getchar()),若輸入 ni hao ,c或者d; } } }

int check(char arr[]。 #include ”

for(i=0; }

return count; puts(“); #define ROWS 256

#define COLS 32---定義「字典」的大小;

char *pt[ROWS];t\

if((fp=fopen(”

puts(”

if(strncmp(a[i],請不要點DOS窗口的小叉叉;

char ptr[ROWS][COLS];END”請輸入單詞(每行一個)”

puts(“d’?”n\,j,b, i)) continue,”, int count),start;t*********************歡迎使用字典排版系統*******************\%s”

static char a[ROWS][COLS],然後要求輸入單詞, a[i])==1) {

fflush(stdin); c(pt; puts(pt[i]),fp);重複的單詞;b’ctype.h”ROWS;\?”,SEEK_END););

puts(“,fp)==0) { i=0,並加以處理;

i=count; }

void storage(char *pt[]. 添加新單詞”。

#include “---定義數組,防止誤操作; rewind(fp);i請輸入a;在新行輸入END結束輸入,並存儲到文件中;

int check(char arr[],”i++)

if(strncmp(a[i];n’!=’;該數組的作用是將文件的內容複製進來;c’ }

for(i=0;words。因為程序在結束之前;

for(i=0;count; “. 對已有的單詞進行排序 d; int main(void) {

int i.h”))==NULL) {

fputs(“n”,”i,pt[j]) }

char get_option(void) {

char ch;

return 0;n\;

void c(char *pt[]; flag=1; #include “!”:”).”

while(icount,實際數組元素位置未改變;n” }

fflush(stdin),對數組中的單詞重新排序; count=b(count);d’ char input;i++) if(isalpha(arr[i])==0) {

printf(“);

puts(“,strlen(a[count])+1)==0) {

puts(“c; while((input=get_option()); #include ” pt[i]=pt[j];a; fclose(fp);i:內部鏈接;%s”您要做些什麼;j++) ptr[i][j]=pt[i][j];stdlib;);;stdlib;\, int count);

char *temp.h”.h”

fp=fopen(“---完成選項c的作用--通過指針對數組排序; for(i=0;---完成選項b的作用--接收新單詞;32,count;;a+”) ; i++;

if(fread(a. 退出”。因為處理數組比處理文件方便;) {

puts(“:可存放256個單詞; } i++;---

#include “||ch exit(1); }

fseek(fp; rewind(fp);)

{

if(input==’!=’,輸入d即可, count),文件作用域;%s不是一個單詞; #include “‘);n”0) {

temp=pt[i];ROWSscanf(“, int count),並且提示並剔除重複的單詞;謝謝使用;w+” flag=1程序第一次運行時.txt”, int count) { int i,將視為單詞 ni ; } }

puts(“j++) {

if(strcmp(pt[i];

puts(”

c(pt;請輸入新的單詞(每行一個)” #include ” count=start,”

fwrite(ptr; if(check(a[i]

回復:

#includestdio.h

#includestring.h

void main()

{

char str[30];

scanf(“%s”,str);

if(strcmp(str,”em”)==0)

printf(“them\n”);

else if(strcmp(str,”cuz”)==0)

printf(“because\n”);

else if(strcmp(str,”gratz”)==0)

printf(“grateful\n”);

else if(strcmp(str,”i”)==0)

printf(“I\n”);

else if(strcmp(str,”nah”)==0)

printf(“no\n”);

else if(strcmp(str,”pos”)==0)

printf(“them\n”);

else if(strcmp(str,”sez”)==0)

printf(“supoosed\n”);

else if(strcmp(str,”tanz”)==0)

printf(“thanks\n”);

else if(strcmp(str,”wuz”)==0)

printf(“was\n”);

else

printf(“cannot find any words\n”);

}//試驗過了

回復:

for(int i = 0, string[j]) ;比較字元串大小, string[i]) , string[j]) == 1)//:\

int main()

{

char string[10][50].h i++)

scanf(” i

strcpy(string[j]; j++)

if(strcmp(string[i]; 5; i++ )

for(int j = i+1.h*冒泡排序*/

#include , temp) ;

for(int i = 0; j ); i

}

/

}

PS;/);

for(int i = 0;

printf(“, temp[50];

/string; 6;stdio;

return 0;n” 6:\/ i++ )

puts(string[i]),可以用strcmp

{

strcpy(temp;%s”輸出排好序的6個單詞;/輸出

printf(“;n”請輸入6個單詞;交換要strcpy

strcpy(string[i]; 6, string[i]); i #include :若有不明白的地方

如何編輯c語言程序把一個單詞譯成另一個單詞

#includestdio.h

main()

{

char c1,c2,c3,c4,c5,d1,d2,d3,d4,d5;

c1=C;

c2=h;

c3=i;

c4=n;

c5=a;

d1=c1+4;

d2=c2+4;

d3=c3+4;

d4=c4+4;

d5=c5+4;

printf(“%d%d%d%d%d”,d1,d2,d3,d4,d5);

}

只要ASCII碼加4就可以了,哪裡不懂再問我,QQ:527709313

用C語言實現單詞轉換

****************************

FileName: WordCount.cpp

Author: cox Version : 1.0 Date: 2007/1/12

Description: 文件中指定單詞個數的統計

Version: 1.0

Function List:

1. TransformFile() // 將文件轉換為有效的格式

2. CountWord() // 單詞計數

3. IsValidChar() // 檢查是否有效的英語字母

4. GetInput() // 從輸入流讀取數據

5. UpperCase() // 字元強制轉換為大寫

History:

author time version desc

cox 2007/1/12 1.0 build this moudle

***************************************************/

#include iostream

#include fstream

#include string

using namespace std;

#include “linklist\\linklist.h”

bool TransformFile( char* inFile, char* outFile );

template typename datatype

bool CountWord( char* filename, LinkListdatatype list );

bool IsValidChar( char ch );

template typename datatype

bool GetInput( LinkListdatatype list );

bool UpperCase( string str );

/*************************************************

Function: main()

Description: 主函數

Calls: 鏈表類, TransformFile(), GetInput(),

CountWord()

Called By: 無

Table Accessed: 無

Table Updated: 無

Input: 無

Output: 結果

Return: 0

Others: 無

*************************************************/

int main()

{

LinkListstring wordList;

TransformFile( “test1.txt”, “test1.tmp” );

if ( !GetInput( wordList ) )

{

cout “Bad input!!” endl;

}

if ( !CountWord( “test1.tmp”, wordList ) )

{

cout “An error accord dring count!!” endl;

}

return 0;

}

/*************************************************

Function: TransformFile()

Description: 將文件去掉標點符號, 並按照單詞以空格分組

Calls: IsValidChar()

Called By: main()

Table Accessed: 無

Table Updated: 無

Input: char* inFile // 輸入文件名

char* outFile // 輸出文件名

Output: 狀態

Return: 操作是否成功

Others: 無

*************************************************/

bool TransformFile( char* inFile, char* outFile )

{

ofstream outFileStream( outFile, ios::out );

ifstream inFileStream ( inFile , ios::in );

if ( !outFileStream || !inFileStream )

{

cout “Open files error!!” endl;

return false;

}

char readChar = ‘\0’;

cout “Transfroming…”;

// 轉換

while ( inFileStream.get(readChar) )

{

if ( IsValidChar(readChar) )

{

outFileStream readChar;

}

else

{

outFileStream ” “;

}

}

cout “OK\n”;

outFileStream.close();

inFileStream.close();

return true;

}

/*************************************************

Function: IsValidChar()

Description: 檢查是否有效的英語字元

Calls: 無

Called By: TransformFile()

Table Accessed: 無

Table Updated: 無

Input: char ch // 待檢查的字元

Output: 無

Return: true為是

Others: 無

*************************************************/

bool IsValidChar( char ch )

{

if ( (ch = 65 ch = 90) || (ch = 97 ch = 122) )

{

return true;

}

else

{

return false;

}

}

/*************************************************

Function: GetInput()

Description: 讀取輸入流並存入鏈表中

Calls: 鏈表類

Called By: main()

Table Accessed: 無

Table Updated: 無

Input: LinkListdatatype list // 儲存輸入數據的鏈表

Output: 無

Return: 操作是否成功, true為成功

Others: 無

*************************************************/

template typename datatype

bool GetInput( LinkListdatatype list )

{

string strInput = “”;

cout “Input your words to count, split by \’,\’: “;

cin strInput;

string tmpString = “”;

strInput += “,”;

for ( int index = 0; index strInput.size(); index++ )

{

if ( strInput[index] == ‘,’ )

{

list.Insert(tmpString);

tmpString = “”;

}

else

{

tmpString += strInput[index];

}

}

return true;

}

/*************************************************

Function: CountWord()

Description: 單詞計數

Calls: 鏈表類, UpperCase()

Called By: main()

Table Accessed: 無

Table Updated: 無

Input: char* filename // 待計數的文件

LinkListdatatype list // 儲存輸入數據的鏈表

Output: 無

Return: 操作是否成功, true為成功

Others: 無

*************************************************/

template typename datatype

bool CountWord( char* filename, LinkListdatatype list )

{

ifstream inFileStream ( filename , ios::in );

int lenth = list.Lenth();

int *counts = new int [lenth];

for ( int clrIndex = 0; clrIndex list.Lenth(); clrIndex++ )

{

counts[clrIndex] = 0;

}

string tmpString;

string tmpRead;

while ( inFileStream tmpRead )

{

for ( int index = 0; index list.Lenth(); index++ )

{

list.Locate(index+1);

tmpString = list.Peek();

UpperCase( tmpString );

UpperCase( tmpRead );

if ( tmpString == tmpRead )

{

counts[index]++;

}

}

}

for ( int index = 0; index lenth; index++ )

{

list.Locate(index+1);

tmpString = list.Peek();

cout tmpString ” = ” counts[index] endl;

}

cout endl;

inFileStream.close();

return true;

}

/*************************************************

Function: UpperCase()

Description: 強制轉換成大寫

Calls: 無

Called By: CountWord()

Table Accessed: 無

Table Updated: 無

Input: string str // 待轉換的字元

Output: 無

Return: 操作是否成功, true為成功

Others: 無

*************************************************/

bool UpperCase( string str )

{

for ( int index = 0; index str.size(); index++ )

{

if ( str[index] 96 )

{

str[index] -= 32;

}

}

return true;

}

需要鏈表,自己寫一個吧,大一就該學了的~~

原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/280916.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
小藍的頭像小藍
上一篇 2024-12-21 13:05
下一篇 2024-12-21 13:05

相關推薦

  • AES加密解密演算法的C語言實現

    AES(Advanced Encryption Standard)是一種對稱加密演算法,可用於對數據進行加密和解密。在本篇文章中,我們將介紹C語言中如何實現AES演算法,並對實現過程進…

    編程 2025-04-29
  • 學習Python對學習C語言有幫助嗎?

    Python和C語言是兩種非常受歡迎的編程語言,在程序開發中都扮演著非常重要的角色。那麼,學習Python對學習C語言有幫助嗎?答案是肯定的。在本文中,我們將從多個角度探討Pyth…

    編程 2025-04-29
  • Python被稱為膠水語言

    Python作為一種跨平台的解釋性高級語言,最大的特點是被稱為”膠水語言”。 一、簡單易學 Python的語法簡單易學,更加人性化,這使得它成為了初學者的入…

    編程 2025-04-29
  • OpenJudge答案1.6的C語言實現

    本文將從多個方面詳細闡述OpenJudge答案1.6在C語言中的實現方法,幫助初學者更好地學習和理解。 一、需求概述 OpenJudge答案1.6的要求是,輸入兩個整數a和b,輸出…

    編程 2025-04-29
  • Python按位運算符和C語言

    本文將從多個方面詳細闡述Python按位運算符和C語言的相關內容,並給出相應的代碼示例。 一、概述 Python是一種動態的、面向對象的編程語言,其按位運算符是用於按位操作的運算符…

    編程 2025-04-29
  • Python如何轉換小寫字母

    Python提供了一些簡單而有效的方法來處理字元串,包括下列方法,可以用來將字元串轉換為小寫字母。 一、lower() lower()是Python中內置的字元串方法之一,可以將字…

    編程 2025-04-29
  • Python語言由荷蘭人為中心的全能編程開發工程師

    Python語言是一種高級語言,很多編程開發工程師都喜歡使用Python語言進行開發。Python語言的創始人是荷蘭人Guido van Rossum,他在1989年聖誕節期間開始…

    編程 2025-04-28
  • Python中字母代表的數字

    在Python中,我們經常會用到英文字母作為數字的代表,例如表示布爾值的True和False,表示空值的None等等。本文將從多個方面對Python中字母代表的數字進行詳細的闡述,…

    編程 2025-04-28
  • Python語言設計基礎第2版PDF

    Python語言設計基礎第2版PDF是一本介紹Python編程語言的經典教材。本篇文章將從多個方面對該教材進行詳細的闡述和介紹。 一、基礎知識 本教材中介紹了Python編程語言的…

    編程 2025-04-28
  • Python語言實現人名最多數統計

    本文將從幾個方面詳細介紹Python語言實現人名最多數統計的方法和應用。 一、Python實現人名最多數統計的基礎 1、首先,我們需要了解Python語言的一些基礎知識,如列表、字…

    編程 2025-04-28

發表回復

登錄後才能評論