C字符串未运行

时间:2018-03-03 10:28:47

标签: c scanf

由于我是新手程序员和编码器所以,我在Hackerrank中花了30天的编码挑战,但是当我在C中运行简单的字符串存储问题时,它显示没有错误 守则

#include <stdio.h>
int main() {
    int i = 4;
    double d = 4.0;
    char s[] = "HackerRank ";
    // Declare second integer, double, and String variables.

    // Read and save an integer, double, and String to your variables.

    // Print the sum of both integer variables on a new line.

    // Print the sum of the double variables on a new line.

    // Concatenate and print the String variables on a new line
    // The 's' variable above should be printed first.
int ie;double de;char re[1000];
printf("Enter the int,double,string value :");
scanf("%d %lf %s",&ie,&de,re);
printf("\n%d\n%lf\n%s",(ie+i),(de+d),s);
printf("%s\n",re);
 return 0;
}

输入:

12 
4.0
is the best place to learn

预期产出:

16
8.0
HackerRank is the best place to learn

实际输出:

Enter the int,double,string value :
16
8.000000
HackerRank is

1 个答案:

答案 0 :(得分:0)

这可能会有所帮助:

#include <stdio.h>

int main() {
    int i = 4;
    double d = 4.0;
    char s[] = "HackerRank ";
    int x;
    double y;
    char z[50];
    scanf(" %d %lf\n%[^\n]", &x, &y, z);
    printf("%d\n", x+i);
    printf("%.1lf\n", y+d);
    printf("%s", s);
    printf("%s", z);
    return 0;
}