读取输入的多行与scanf函数 [英] Reading multiple lines of input with scanf

查看:96
本文介绍了读取输入的多行与scanf函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

写作类节目,只限于scanf函数方法。程序接收到可以接收任意数量的行作为输入。麻烦接收多条线路输入,scanf函数。

Writing a program for class, restricted to only scanf method. Program receives can receive any number of lines as input. Trouble with receiving input of multiple lines with scanf.

#include <stdio.h>
int main(){
    char s[100];
    while(scanf("%[^\n]",s)==1){
        printf("%s",s);
    }
    return 0;
}

输入示例:

Here is a line.
Here is another line.

这是电流输出:

Here is a line.

我希望我的输出是相同的,以我的意见。使用scanf函数。

I want my output to be identical to my input. Using scanf.

推荐答案

试试这个code和使用Tab键作为分隔符

try this code and use tab key as delimeter

#include <stdio.h>
int main(){
    char s[100];
    scanf("%[^\t]",s);
    printf("%s",s);

    return 0;
}

这篇关于读取输入的多行与scanf函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆