所以我正在学习C编程语言,我想运行一个基本脚本,其中用户输入一个变量,打印出来的变量是用户输入的变量,这很简单,但是,代码我写了一些与代码无关的随机内容,请帮忙。
#include <stdio.h>
char main(void){
char var[3];
printf("Enter your name: ");
scanf("%1f", &var);
printf("%s", &var);
}
答案 0 :(得分:0)
#include <stdio.h>
void main(void){
char var[20];
printf("Enter your name: \n");
scanf("%s", var); // Note: %s is for char arrays and not %f(floats)
printf("%s", var); // Note: no ampersand here
}
答案 1 :(得分:-1)
有很多方法可以回答你的问题。首先,让我们按照你的例子的方式去做。每行的说明都在旁边。
示例1:
#include <stdio.h> //You are require this header to do the basic C stuff
void main(void){ //Main loop to run your code
char var[3]; //An array to store data
printf("Enter your name: ");
scanf("%s", &var); //I removed 1f because you don't require 1 and f is float only
printf("%s", &var);
}
示例2:
#include <stdio.h> //You are require this header to do the basic C stuff
main(){ // Main loop to run your code
char var; //An char var to store data
printf("Enter your name: ");
scanf("%c", &var);
printf("%c", &var);
}