Chinaunix

标题: c里面怎么获取输入,这个问题很白,谁愿意告诉我? [打印本页]

作者: simhare    时间: 2009-06-30 14:53
标题: c里面怎么获取输入,这个问题很白,谁愿意告诉我?
其实就是刚才的帖子的延伸的问题:
刚才的帖子:
http://bbs3.chinaunix.net/thread-1494360-1-1.html
---------------
#include <stdio.h>
#include <stdlib.h>
#include "atmi.h"

main(argc, argv)
{
        long reqlen=1024;
        char *reqbuf;
        /* create connection to server side of tuxedo */
        if(tpinit((TPINIT *)NULL)==-1)
        {
                (void)fprintf(stderr, "Tpinit failed!\n");
                exit(1);
        }

        /* allocate buffer of send */
        reqbuf=(char *)tpalloc("STRING", NULL, reqlen);
        if(reqbuf==(char *)NULL)
        {
                printf("tpalloc failed!\n");
                tpterm();
        }
        strcpy(reqbuf, "7844");------我怎么获得用户的键盘输入?而不是这样写死呢

        /* call service TEST1 */
        if(tpcall("TEST1", (char *)reqbuf, 0L, (char **)&reqbuf, (long *)&reqlen, 0)<0)
        {
                printf("tpcall failed, tperrno=%ld, tperrtext=%s\n", tperrno, tpstrerror(tperrno));
                tpfree(reqbuf);
                tpterm();
                exit(1);
        }

        printf("name=%s\n", reqbuf);
        tpfree(reqbuf);
        tpterm();
        return (0);
}
==============
我用以上这个c程序作客户端,去调用Tuxedo的服务TEST1,

[ 本帖最后由 simhare 于 2009-6-30 14:56 编辑 ]
作者: yug1129    时间: 2009-06-30 14:53
标题: 是不是要这个?
把strcpy(reqbuf, "7844");改为

scanf("%s", buf);
strcpy(reqbuf, buf);

buf的定义是
char buf[BUFSIZ];
作者: ziggler    时间: 2009-06-30 15:01
标题: 回复 #1 simhare 的帖子
http://c-faq.com/osdep/cbreak.html
获取输入字符 - C/C++ - ChinaUnix.net (30 June 2009)
http://bbs.chinaunix.net/viewthread.php?tid=1065846
作者: blackuhlan    时间: 2009-06-30 16:46
getchar()
scanf()
ioctl()
and so on
作者: mgqw    时间: 2009-06-30 16:59
晕,这是最最基础的东西。
用scanf函数
scanf(格式控制字符串,参数表)
作者: ubuntuer    时间: 2009-06-30 19:19
LZ估计是刚接触c滴
作者: eveson    时间: 2009-06-30 19:36
c语言基础教程看了吗
作者: simhare    时间: 2009-07-02 09:41
标题: 回复 #2 yug1129 的帖子
为什么我用gets取得用户输入的时候,会收到警告信息,而用scanf就不会?
作者: simhare    时间: 2009-07-02 09:42
标题: 回复 #8 simhare 的帖子
谁知道scanf 和gets在取得用户键盘输入方面有什么区别?
作者: gawk    时间: 2009-07-02 09:46
原帖由 simhare 于 2009-7-2 09:42 发表
谁知道scanf 和gets在取得用户键盘输入方面有什么区别?

你为何不man一下了
man scanf
man gets
作者: yulihua49    时间: 2009-07-02 14:06
原帖由 simhare 于 2009-7-2 09:41 发表
为什么我用gets取得用户输入的时候,会收到警告信息,而用scanf就不会?



while(!ferror(stdin)) {
             printf("Input:");
             fflush(stdout);
             fgets(buf,sizeof(buf),stdin);
             if(feof(stdin)) break;
    .....................
}




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2