c程序设计语言_习题1-19_编写函数reverse(s)将字符串s中字符顺序颠倒过来。
Write a function reverse(s) that reverses the character string s . Use it to write a program that reverses its input a line at a time.
#include <stdio.h> #define MAX_LINE 1024 void discardnewline(char s[])
{
int i;
for(i = ; s[i] != '\0'; i++)
{
if(s[i] == '\n')
s[i] = '\0';
}
} int reverse(char s[])
{
char ch;
int i, j; for(j = ; s[j] != '\0'; j++)
{
} --j; for(i = ; i < j; i++)
{
ch = s[i];
s[i] = s[j];
s[j] = ch;
--j;
} return ;
} int getline(char s[], int lim)
{
int c, i; for(i = ; i < lim - && (c = getchar()) != EOF && c != '\n'; ++i)
{
s[i] = c;
} if(c == '\n')
{
s[i++] = c;
} s[i] = '\0'; return i; } int main(void)
{
char line[MAX_LINE]; while(getline(line, sizeof line) > )
{
discardnewline(line);
reverse(line);
printf("%s\n", line);
}
return ;
}
c程序设计语言_习题1-19_编写函数reverse(s)将字符串s中字符顺序颠倒过来。的更多相关文章
- c程序设计语言_习题1-16_自己编写getline()函数,接收整行字符串,并完整输出
Revise the main routine of the longest-line program so it will correctly print the length of arbitra ...
- c程序设计语言_习题8-6_利用malloc()函数,重新实现c语言的库函数calloc()
The standard library function calloc(n,size) returns a pointer to n objects of size size , with the ...
- c程序设计语言_习题1-9_将输入流复制到输出流,并将多个空格过滤成一个空格
Write a program to copy its input to its output, replacing each string of one or more blanks by a si ...
- c程序设计语言_习题7-6_对比两个输入文本文件_输出它们不同的第一行_并且要记录行号
Write a program to compare two files, printing the first line where they differ. Here's Rick's solut ...
- c程序设计语言_习题8-4_重新实现c语言的库函数fseek(FILE*fp,longoffset,intorigin)
fseek库函数 #include <stdio.h> int fseek(FILE *stream, long int offset, int origin); 返回:成功为0,出错 ...
- c程序设计语言_习题1-18_删除输入流中每一行末尾的空格和制表符,并删除完全是空格的行
Write a program to remove all trailing blanks and tabs from each line of input, and to delete entire ...
- c程序设计语言_习题1-13_统计输入中单词的长度,并且根据不同长度出现的次数绘制相应的直方图
Write a program to print a histogram of the lengths of words in its input. It is easy to draw the hi ...
- c程序设计语言_习题1-11_学习单元测试,自己生成测试输入文件
How would you test the word count program? What kinds of input are most likely to uncover bugs if th ...
- 网易云课堂_程序设计入门-C语言_第五周:函数_2完数
2 完数(5分) 题目内容: 一个正整数的因子是所有可以整除它的正整数.而一个数如果恰好等于除它本身外的因子之和,这个数就称为完数.例如6=1+2+3(6的因子是1,2,3). 现在,你要写一个程序, ...
随机推荐
- C++ 中的“ !” 运算
在介绍“ !”运算之前,我们要知道一个变量n,如果n>0,那么我们可以在逻辑上叫它“真”,如果n<=0 ,那么我们可以在逻辑上叫它“假”. n为真时,!n就为假(false),转换为整型值 ...
- Spring MVC中Ajax实现二级联动
今天写项目遇到了二级联动,期间遇到点问题,写个博客记录一下. 后台Controller: @RequestMapping("/faultType") @ResponseBody p ...
- (转载)Delphi开发经验谈
Delphi开发经验谈 开发环境-------- Delphi 7是一个很经典的版本,在Win2000/XP下推荐安装Delphi 7来开发软件,在Vista下推荐使用Delphi 2007开发软件. ...
- ZeroMQ/jzmq安装使用
环境: No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 12.04.2 LTS Release: 12 ...
- 在前后端分离Web项目中,RBAC实现的研究
最近手头公司的网站项目终于渐渐走出混沌,走上正轨,任务也轻松了一些,终于有时间整理和总结一下之前做的东西. 以往的项目一般使用模板引擎(如ejs)渲染出完整页面,再发送到浏览器展现.但这次项目的处理方 ...
- 【DB】SQLite学习笔记
下载”System.Data.SQLite.DLL”,程序中添加引用即可 //创建数据库文件 SQLiteConnection.CreateFile("sqlitetest.db" ...
- SGU 194 Reactor Cooling Dinic求解 无源无汇有上下界的可行流
题目链接 题意:有向图中有n(1 <= n <= 200)个点,无自环或者环的节点个数至少为3.给定每条边的最小流量和最大流量,问每条边的可行流量为多少? 思路:一般求解的网络流并不考虑下 ...
- Centos 6.2上安装使用 Informix11.70 数据库
环境要求:操作系统: Centos 6.2 32位数据库软件: iif.11.70.UC7IE.Linux-RHEL5.tar(在IBM网站上注册个帐号就可以下载,包括windows,Linux,Un ...
- windows azure programing
http://azure.microsoft.com/en-us/documentation/articles/web-sites-dotnet-get-started-vs2012/ http:// ...
- ASP.NET MVC 3 Razor Views in SharePoint
http://tqcblog.com/2011/01/22/asp-net-mvc-3-razor-views-in-sharepoint/ ASP.NET MVC 3 has just been r ...