免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 5783 | 回复: 12

getline (fp)问题求教,谢谢 [复制链接]

论坛徽章:
0
发表于 2011-08-18 16:16 |显示全部楼层
本帖最后由 rwxgold 于 2011-08-18 16:18 编辑

  1. /*
  2. * tftp - Trivial File Transfer Program.  Client side.
  3. *
  4. * See RFC 783 for details.  Also see the "Requirements for Internet Hosts"
  5. * RFC for additional explanations and clarifications.
  6. */

  7. #include        "defs.h"
  8. #include <signal.h>
  9. #include <sys/types.h>
  10. #include <sys/socket.h>
  11. #include <netdb.h>
  12. #include <string.h>
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <string.h>
  16. #include <unistd.h>




  17. int main(int argc, char *argv[])
  18. {
  19.         register int        i;
  20.         register char        *s;
  21.         register FILE        *fp;


  22.         pname = argv[0];

  23.         while (--argc > 0 && (*++argv)[0] == '-')
  24.                 for (s = argv[0]+1; *s != '\0'; s++)
  25.                         switch (*s) {

  26.                         case 'h':                /* specify host name */
  27.                                 if (--argc <= 0)
  28.                                    err_quit("-h requires another argument");
  29.                                 strcpy(hostname, *++argv);
  30.                                 break;

  31.                         case 't':
  32.                                 traceflag = 1;
  33.                                 break;

  34.                         case 'v':
  35.                                 verboseflag = 1;
  36.                                 break;

  37.                         default:
  38.                                 err_quit("unknown command line option: %c", *s);
  39.                         }

  40.         /*
  41.          * For each filename argument, execute the tftp commands in
  42.          * that file.  If no filename arguments were specified on the
  43.          * command line, we process the standard input by default.
  44.          */

  45.         i = 0;
  46.         fp = stdin;
  47.         do {
  48.                 if (argc > 0 && (fp = fopen(argv[i], "r")) == NULL) {
  49.                         err_sys("%s: can't open %s for reading", argv[i]);
  50.                 }

  51.                 mainloop(fp);                /* process a given file */

  52.         } while (++i < argc);

  53.         exit(0);
  54. }

  55. mainloop(fp)
  56. FILE        *fp;


  57. {
  58.         void sig_intr();

  59.         if (signal(SIGINT, SIG_IGN) != SIG_IGN)
  60.                 signal(SIGINT, sig_intr);

  61.         /*
  62.          * Main loop.  Read a command and execute it.
  63.          * This loop is terminated by a "quit" command, or an
  64.          * end-of-file on the command stream.
  65.          */

  66.         if (setjmp(jmp_mainloop) < 0) {
  67.                 err_ret("Timeout");
  68.         }

  69.         if (interactive)
  70.                 printf("%s", prompt);

  71.         while (getline (fp)) {
  72.                 if (gettoken(command) != NULL)
  73.                         docmd(command);

  74.                 if (interactive)
  75.                         printf("%s", prompt);
  76.         }
  77. }

  78. /*
  79. * INTR signal handler.  Just return to the main loop above.
  80. * In case we were waiting for a read to complete, turn off any possible
  81. * alarm clock interrupts.
  82. *
  83. * Note that with TFTP, if the client aborts a file transfer (such as with
  84. * the interrupt signal), the server is not notified.  The protocol counts
  85. * on the server eventually timing out and exiting.
  86. */

  87. void
  88. sig_intr()
  89. {
  90.         signal(SIGALRM, SIG_IGN);        /* first ignore the signal */
  91.         alarm(0);                        /* then assure alarm is off */

  92.         longjmp(jmp_mainloop, 1);
  93.         /* NOTREACHED */
  94. }
复制代码
测试一个源代码,但是编译老是出错,请高手指点一下,谢谢!

调试后出现以下错误:
--------------------------------------

test@ubuntu:~/Desktop/mytftp$ make -f makefile
cc    -c -o client.o client.c
client.c: In function ‘mainloop’:
client.c:96: warning: passing argument 1 of ‘getline’ from incompatible pointer type
/usr/include/stdio.h:651: note: expected ‘char ** __restrict__’ but argument is of type ‘struct _IO_FILE *’
client.c:96: error: too few arguments to function ‘getline’
make: *** [client.o] Error 1
---------------------------------------
系统是ubuntu-10.04.3-desktop-i386

谢谢
------------------------------------------------------

系统是Ubuntu

论坛徽章:
1
CU十二周年纪念徽章
日期:2013-10-24 15:41:34
发表于 2011-08-18 16:20 |显示全部楼层
LZ,看错误描述啊,说得很清楚啊。

论坛徽章:
0
发表于 2011-08-18 16:22 |显示全部楼层
偶是初学者,楼上的大哥请教如何改啊?

论坛徽章:
1
CU十二周年纪念徽章
日期:2013-10-24 15:41:34
发表于 2011-08-18 16:41 |显示全部楼层
回复 3# rwxgold


   
XXX
XXX WARNING: old character encoding and/or character set
XXX
GETLINE(3)                 Linux Programmer's Manual                GETLINE(3)

NAME
       getline, getdelim - delimited string input

SYNOPSIS
       #define _GNU_SOURCE
       #include <stdio.h>

       ssize_t getline(char **lineptr, size_t *n, FILE *stream);
       ssize_t getdelim(char **lineptr, size_t *n, int delim, FILE *stream);

DESCRIPTION
       getline() reads an entire line from stream, storing the address of the buffer containing the
       text into *lineptr.  The buffer is null-terminated and includes the  newline  character,  if
       one was found.

       If  *lineptr  is  NULL,  then  getline()  will allocate a buffer for storing the line, which
       should be freed by the user program.  Alternatively, before calling getline(), *lineptr  can
       contain  a  pointer  to  a  malloc()-allocated buffer *n bytes in size. If the buffer is not
       large enough to hold the line, getline() resizes it with realloc(), updating *lineptr and *n
       as  necessary.  In  either  case,  on  a successful call, *lineptr and *n will be updated to
       reflect the buffer address and allocated size respectively.

论坛徽章:
0
发表于 2011-08-18 17:02 |显示全部楼层
嘎嘎。。。man它一下

论坛徽章:
0
发表于 2011-08-18 17:04 |显示全部楼层
回复 4# ecjtubaowp


    按照这个,貌似还是调试出错耶!是不是Ubantu版本问题啊?~ 请指教,谢谢

论坛徽章:
0
发表于 2011-08-18 17:15 |显示全部楼层
回复 6# rwxgold


    继续贴错误啊!

论坛徽章:
0
发表于 2011-08-18 17:29 |显示全部楼层
回复 7# jiayanfu


    MAN过了,命令是一样的

论坛徽章:
0
发表于 2011-08-18 17:30 |显示全部楼层
错误是一样的?把你盖好的那一句贴一下

论坛徽章:
0
发表于 2011-08-18 17:38 |显示全部楼层
回复 9# jiayanfu


    ssize_t getline(fp))

头也加了 #define _GNU_SOURCE
       #include <stdio.h>
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP