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中字符顺序颠倒过来。的更多相关文章

  1. c程序设计语言_习题1-16_自己编写getline()函数,接收整行字符串,并完整输出

    Revise the main routine of the longest-line program so it will correctly print the length of arbitra ...

  2. c程序设计语言_习题8-6_利用malloc()函数,重新实现c语言的库函数calloc()

    The standard library function calloc(n,size) returns a pointer to n objects of size size , with the ...

  3. c程序设计语言_习题1-9_将输入流复制到输出流,并将多个空格过滤成一个空格

    Write a program to copy its input to its output, replacing each string of one or more blanks by a si ...

  4. c程序设计语言_习题7-6_对比两个输入文本文件_输出它们不同的第一行_并且要记录行号

    Write a program to compare two files, printing the first line where they differ. Here's Rick's solut ...

  5. c程序设计语言_习题8-4_重新实现c语言的库函数fseek(FILE*fp,longoffset,intorigin)

      fseek库函数 #include <stdio.h> int fseek(FILE *stream, long int offset, int origin); 返回:成功为0,出错 ...

  6. c程序设计语言_习题1-18_删除输入流中每一行末尾的空格和制表符,并删除完全是空格的行

    Write a program to remove all trailing blanks and tabs from each line of input, and to delete entire ...

  7. 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 ...

  8. c程序设计语言_习题1-11_学习单元测试,自己生成测试输入文件

    How would you test the word count program? What kinds of input are most likely to uncover bugs if th ...

  9. 网易云课堂_程序设计入门-C语言_第五周:函数_2完数

    2 完数(5分) 题目内容: 一个正整数的因子是所有可以整除它的正整数.而一个数如果恰好等于除它本身外的因子之和,这个数就称为完数.例如6=1+2+3(6的因子是1,2,3). 现在,你要写一个程序, ...

随机推荐

  1. 九度OJ 1512 用两个栈实现队列 【数据结构】

    题目地址:http://ac.jobdu.com/problem.php?pid=1512 题目描述: 用两个栈来实现一个队列,完成队列的Push和Pop操作. 队列中的元素为int类型. 输入: 每 ...

  2. linksys wrt160nv3 刷dd-wrt固件

    家中有个闲置的wrt160nv3路由器,无意中在网上发现可以刷dd-wrt固件来实现更多功能.目前家里电信光猫F460的自带无线使用起来不是很稳定,就想把wrt160nv3刷成dd-wrt来当做一个A ...

  3. Redis和Memcache的区别分析 [转]

    1. Redis中,并不是所有的数据都一直存储在内存中的,这是和Memcached相比一个最大的区别. 2. Redis不仅仅支持简单的k/v类型的数据,同时还提供list,set,hash等数据结构 ...

  4. PHP权限分配思路

    常见四种方式1.用户+组+角色+权限2.用户+组+权限3.用户+角色+权限(最多用)4.用户+权限以第三种为例:权限:用户操作的具体事件:如curd角色:指一类用户拥有的权限,如超级管理员,管理员,普 ...

  5. 【5】了解Bootstrap预置的栅格系统

    在开篇之前我们来说2个class,因为以后要用到的 <div class="container"> ... </div> 用.container包裹页面上的 ...

  6. opengl混合效果

    效果如下图:

  7. css helper class

    应该习惯的css helper class .text-centered text-align: center; .text-right text-align: right; .small small ...

  8. E8.Net工作流平台之中国特色

     特色之一领导排名有先后 领导排名是有潜规则的,不论是在企业通讯录中,还是企业员工目录中,不管在流程执行过程中,还是存档数据中,当前领导的排名一定要按潜规则展示,不能随便罗列.E8.Net工作流解决了 ...

  9. Lucene基础(三)-- 中文分词及高亮显示

    Lucene分词器及高亮 分词器 在lucene中我们按照分词方式把文档进行索引,不同的分词器索引的效果不太一样,之前的例子使用的都是标准分词器,对于英文的效果很好,但是中文分词效果就不怎么样,他会按 ...

  10. CoreBluetooth - 中心模式

    BLE中心模式流程-coding BLE中心模式流程 - 1.建立中心角色 - 2.扫描外设(Discover Peripheral) - 3.连接外设(Connect Peripheral) - 4 ...