exercise1-17

 

exercise1-17: Write a program to print all input lines that are longer than 80 characters.

#include<stdio.h>
#define MAXLINE 1000
#define LIMIT 80

int getlines(char line[],int maxline);
void copy(char to[], char from[]);

/*print the lines more than 80*/
main()
{
   int len ; /*current line length*/
   char line[LIMIT];  /*current input line*/
   char longer[LIMIT]; /*longer line saved here*/

   while((len = getlines(line,MAXLINE))>0)
       if(len > LIMIT){
          copy(longer  , line);
       }
   printf("%s", longer);
   return 0;
}

/*getline:read a line into s,return length*/

int getlines(char s[],int lim)
{
   int c,i;

   for(i=0;i<lim-1 && (c=getchar()) != EOF && c != '\n';++i)
       s[i] = c;
   if(c == '\n')
   {
      s[i] = c;
      ++ i;
   }
  s[i] = '\0';
  return i;

}

/*copy:copy 'from' into 'to'*/
void copy(char to[],char from[])
{

   int i;

   i = 0;

   while((to[i] = from[i]) != '\0')
       ++ i;
}


 


"longer.c" 50 lines, 856 characters

 

非常神奇的结果啊:

……………………………………………………………………………………………………………………………………………………………………………………………………………hhhhhhhhhhhhhhhh1234567890-0987654321qawsderfgtyhjuiklop;[poiuytredsxzaqwedcvfrtgbnhyujmkilo
*** stack smashing detected ***: ./a.out terminated
======= Backtrace: =========
/lib/tls/i686/cmov/libc.so.6(__fortify_fail+0x50)[0x1f2390]
/lib/tls/i686/cmov/libc.so.6(+0xe233a)[0x1f233a]
./a.out[0x80484fa]
/lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xe6)[0x126bd6]
======= Memory map: ========
00110000-00263000 r-xp 00000000 08:01 263984     /lib/tls/i686/cmov/libc-2.11.1.so
00263000-00264000 ---p 00153000 08:01 263984     /lib/tls/i686/cmov/libc-2.11.1.so
00264000-00266000 r--p 00153000 08:01 263984     /lib/tls/i686/cmov/libc-2.11.1.so
00266000-00267000 rw-p 00155000 08:01 263984     /lib/tls/i686/cmov/libc-2.11.1.so
00267000-0026a000 rw-p 00000000 00:00 0
00a60000-00a7d000 r-xp 00000000 08:01 133451     /lib/libgcc_s.so.1
00a7d000-00a7e000 r--p 0001c000 08:01 133451     /lib/libgcc_s.so.1
00a7e000-00a7f000 rw-p 0001d000 08:01 133451     /lib/libgcc_s.so.1
00bf0000-00bf1000 r-xp 00000000 00:00 0          [vdso]
00c9a000-00cb5000 r-xp 00000000 08:01 133393     /lib/ld-2.11.1.so
00cb5000-00cb6000 r--p 0001a000 08:01 133393     /lib/ld-2.11.1.so
00cb6000-00cb7000 rw-p 0001b000 08:01 133393     /lib/ld-2.11.1.so
08048000-08049000 r-xp 00000000 08:01 925403     /home/fuyi/a.out
08049000-0804a000 r--p 00000000 08:01 925403     /home/fuyi/a.out
0804a000-0804b000 rw-p 00001000 08:01 925403     /home/fuyi/a.out
09426000-09447000 rw-p 00000000 00:00 0          [heap]
b788f000-b7890000 rw-p 00000000 00:00 0
b789c000-b78a0000 rw-p 00000000 00:00 0
bfaa8000-bfabd000 rw-p 00000000 00:00 0          [stack]
hhhhhhhhhhhhhhhh1234567890-0987654321qawsderfgtyhjuiklop;[poiuytredsxzaqwedcvfrtAborted

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值