所以我正在学习C编程语言,我想运行一个基本脚本,在该脚本中,用户输入一个变量和被打印出的变量是用户输入的一种变量但是,这很简单,我编写的代码是一个随机的东西,与代码无关,请帮助。
#include <stdio.h>
char main(void){
char var[3];
printf("Enter your name: ");
scanf("%1f", &var);
printf("%s", &var);
}
#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:
#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);
}