如何使用其他函数获取结构的用户输入以获取C99中的用户输入

时间:2016-11-23 02:50:31

标签: c struct

我收到错误,因为我需要为此结构添加一个返回值。

struct Item enterItem(int sku)
{
        char name;

        printf("        SKU: %d", sku);
        printf("       Name: "); scanf("%20[^\n]", &name);
        clearKeyboard();                     // Function call to remove'\n'
        printf("      Price: ");
        getDouble();                         // Function call to get user input in double
        printf("   Quantity: ");
        getInt();                            // Function call to get user input in int
        printf("Minimum Qty: ");
        getInt();
        printf("   Is taxed: ");
        getYesOrNo();                        // Function call to get user input in bool > (Y)es or (N)o

}

1 个答案:

答案 0 :(得分:0)

你应该创建一个struture对象(数据)来返回并返回它。

你想要的可能是这样的:

def squares(start, stop):
    for i in range(start, stop):
        yield i * i

generator = squares(1, 10)

print(list(generator))


class Squares(object):
    def __init__(self, start, stop):
        self.start = start
        self.stop = stop

    def __iter__(self):
        return self

    def __next__(self):
        if self.start >= self.stop:
            raise StopIteration
        current = self.start * self.start
        self.start += 1
        return current


iterator = Squares(1, 10)

l = [next(iterator) for _ in range(1,10)]
print(l)