资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

c语言单词怎么转换成函数 C语言转换函数

用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;

}

需要链表,自己写一个吧,大一就该学了的~~

C语言 怎么编写把原文转换成函数???

#include stdio.h

long f(int n)

{

long term=1;

for (int i=1; i=n; i++)

{

term = term * i;

}

return term;

}

main()

{

int i, j, n;

long term, sum = 0;

printf("Input n:");

scanf("%d", n);

for (i=1; i=n; i++)

{

sum = sum + f(i);

}

printf("1!+2!+…+%d! = %ld\n", n, sum);

}

c语言怎么将字符串转换成对应函数

c语言是没法把字符串转换成对应函数的,c语言是结构化语言,程序怎么执行在编译时已经确定,没法像c#之类的托管代码高级语言能够动态绑定或者叫后期绑定。因为托管代码有运行时去选择执行,而c语言编译后的可执行文件为操作系统直接调用了,所以没法动态绑定。

c语言 改写成函数

能不能说清楚函数的功能

我写一个函数,功能是判断一个字符是数字还是字母

函数名我用的is()你可以随便改

int is(char c)

{

if(c='9'c='0') return 1; //如果是数字,就返回1

else if(c='Z'c='A') return 2; //如果是大写字母,就返回2

else if(c='z'c='a') return 3; //如果是小写字母,就返回3

esle return 0; //啥都不是就返回0

}

int main(void)

{

int i;

char str[80];

gets(str); //输入一个字符串,相当于scanf("%s",str);

for(i=0;str[i]!=0;i++)

switch( is(str[i]) )

{

case 1:printf(" 数字"); break;

case 2: case 3:printf("字母");break;

default:printf("啥都不是");

}

returned 0;

}

如果是初学,你应该是要这种方式吧

不过建议使用上面那种‘

int fun(char str[])

{

int i;

//把你循环那部分放在这里

}

int main(void)

{

char str[80];

gets(str);

fun(str);

returned 0;

}


分享题目:c语言单词怎么转换成函数 C语言转换函数
当前链接:http://cdkjz.cn/article/doogcdg.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220