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). 现在,你要写一个程序, ...
随机推荐
- Where does Windows store MSI files for uninstallation?
Original link: Where does Windows store MSI files for uninstallation? Following content are only use ...
- Xml通用操作类
using System; using System.Collections.Generic; using System.IO; using System.Text; using System.Xml ...
- leetcode Largest Rectangle in Histogram 单调栈
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4052343.html 题目链接 leetcode Largest Rectangle in ...
- 【5】了解Bootstrap预置的栅格系统
在开篇之前我们来说2个class,因为以后要用到的 <div class="container"> ... </div> 用.container包裹页面上的 ...
- Java遍历所有网卡打印对应IP
import java.util.Enumeration; import java.net.*; public class Test { /** * @param args */ public sta ...
- post请求json内容丢失问题
今天在项目组用json传输数据 post方法提交 发现传输过去的数据json内的+ 号被直接干掉了. 后来传输之前直接先编码. 接收端: public void ProcessRequest(Http ...
- C# 目录与文件管理
文件读写 学习了一点点希望对以后的学习工作有帮助 在应用程序中基本任务是对数据的操作,这就是对数据进行访问和保存挤兑数据的读写,应用程序访问一个文本文件叫做“读”:对文本文件的内容进行修改后保存这些修 ...
- 【viewResolver】 springmvc jsp
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> < ...
- 【filter】springmvc web.xml
1.filter用于拦截用户请求,在服务器作出响应前,可以在拦截后修改request和response,这样实现很多开发者想得到的功能. 2.filter实现 ×编写一个继承Filter接口的类 ×在 ...
- spring IOC源码分析(2)
refresh这个方法包含了整个BeanFactory初始化的过程,定位资源由obtainFreshBeanFactory()来完成, protected ConfigurableListableBe ...