编写一条语句,该语句可以接收来自用户的输入以分配给struct [英] Write a statement which can receive input from user to be assigned to struct
本文介绍了编写一条语句,该语句可以接收来自用户的输入以分配给struct的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
struct customer{
char name[30];
int noOfCustomer;
total_pay;
}
问题是编写一条语句,该语句可以接收来自用户的要分配给结构成员的输入,即名称,int noOfCustomer,total_pay;
我可以知道问题在问什么吗?
是不是写了30个这样的结构名称?
the question is write a statement which can receive input from user to be assigned to struct member namely name, int noOfCustomer, total_pay;
may i know what is the question is asking about?
is it write 30 name of the struct name like that?
推荐答案
我认为,您正在寻找类似这样的内容:
I reckon, you are looking for something like this:
struct customer
{
char name[30];
int noOfCustomer;
int total_pay;
};
void Foo()
{
struct customer cust;
scanf("%s", cust.name);
scanf("%d", &cust.noOfCustomer);
scanf("%d", &cust.total_pay);
}
这些是非常基本的问题.因此,如果您只是入门C教科书,您将节省很多时间.
These are very basic questions though. So you''ll save a lot of time if you just get an introductory C text book.
我相信他们会要求您立即输入多个参数. <-不知道我是否正确解释了
使用scanf()
(或其派生词之一)一次引入几个参数:
http://en.wikipedia.org/wiki/Scanf [
I believe they''re asking you to pull in a number of arguments at once. <--Not sure if I interpreted this correctly
Usescanf()
(or one of its derivatives) to pull in several arguments at once:
http://en.wikipedia.org/wiki/Scanf[^]
The name portion of the question, well, that''ll limit your input name buffer to 30 characters, so as long as input doesn''t exceed that. A more bulletproof method would be to use achar *
and dynamically allocate the memory, but that may be a bit too advanced at this stage.
这篇关于编写一条语句,该语句可以接收来自用户的输入以分配给struct的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文