博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
删除字符,用外部函数
阅读量:7259 次
发布时间:2019-06-29

本文共 1211 字,大约阅读时间需要 4 分钟。

题目:一个字符串,内有若干字符,输入一个字符,要求将字符串中该字符删除。用外部函数实现。

编程环境:win7,vs2013.

建立只包含一个函数的四个文件:main函数、输入字符串函数、删除字符函数和输出字符串的函数。

四个文件里的程序如下:

1.主函数。运行会一闪而过,之后直接退出,可以加上“system("pause")”,同时也要加上库文件"stdlib.h"。

1 #include
2 #include
3 4 void main() 5 { 6 extern void enter_string(char str[]); //声明本函数要调用的在其他文件中定义的3各函数 7 extern void delete_string(char str[],char ch); 8 extern void print_string(char str[]); 9 char c; //c是准备删除的字符10 char str[80];11 enter_string(str); //调用enter_string函数,输入字符串12 scanf("%c", &c);13 delete_string(str, c);14 print_string(str);15 system("pause");16 }

2.输入字符串的函数

1 //读入字符串2 #include
3 4 void enter_string(char str[80]) //定义外部函数enter_string5 {6 gets(str);7 }

3.删除字符的函数

1 //删除字符 2 #include
3 void delete_string(char str[], char ch) //定义外部函数delete_string 4 { 5 int i, j; 6 for (i = j = 0; str[i] != '\0';i++) 7 if (str[i] != ch) 8 str[j++] = str[i]; 9 str[j] = '\0';10 }

4.输出字符串的函数

1 //定义外部函数print_string,输出字符串2 #include
3 4 void print_string(char str[])5 {6 printf("%s\n", str);7 }

运行结果

小细节小注意!

转载于:https://www.cnblogs.com/gaigaichen/p/7509373.html

你可能感兴趣的文章
ceph-depoly 部署ceph 集群
查看>>
Jquery 中each循环嵌套的使用示例教程
查看>>
Windows7+VS2012下OpenGL 4的环境配置
查看>>
安全基础-A
查看>>
定义JavaScript类:工厂模式、构造函数模式、原型模式、构造函数原型模式、动态原型模式...
查看>>
zabbix修改Template OS Linux模版使已使用内存(Used memory)更准确
查看>>
OpenStack CEPH Liberty 统一存储 bug解决
查看>>
NAT总结
查看>>
Java-P:对象创建
查看>>
Oracle中的 timestamp 和 timestamp with time zone, timestamp with local time zone
查看>>
【转】MFC中listctrl控件的常用详细总结
查看>>
py django 引入 wiki 模块
查看>>
Logic-算法-分金条
查看>>
页面跳转参数不丢失
查看>>
对于 飞林沙的<把Array说透>的扩展
查看>>
使用shell脚本生成只读权限的sql脚本
查看>>
Add SSH Key to GitLab on Windows
查看>>
浙大复试(二)
查看>>
js深入研究之匿名函数
查看>>
Enabling the Dedicated Administrator Connection (DAC) in SQL Server Express
查看>>