c++ - C4473 warning for structure assignment -
i working on assignment , curious warning when compiling , how remedy it. build when debug error screen. below warning comes up.
1>c:\users\cesteves\documents\c programming\inventory\inventory\inventory.cpp(48): warning c4473: 'scanf_s' : not enough arguments passed format string
note: placeholders , parameters expect 2 variadic arguments, 1 provided
note: missing variadic argument 2 required format string '%s' note: argument used buffer size
#include "stdafx.h" #include <stdio.h> void main() { struct date { int day; int month; int year; }; struct details { char name[20]; int price; int code; int qty; struct date mfg; }; struct details item[50]; int n, i; printf("enter number of items:"); scanf_s("%d", &n); (i = 0; < n; i++) { printf("item name: \n"); scanf_s("%s", item[i].name); printf("item code: \n"); scanf_s("%d", &item[i].code); printf("quantity: \n"); scanf_s("%d", &item[i].qty); printf("price: \n"); scanf_s("%d", &item[i].price); printf("manufacturing date(dd-mm-yyyy): \n"); scanf_s("%d-%d-%d", &item[i].mfg.day, &item[i].mfg.month, &item[i].mfg.year); } printf(" ***** inventory ***** \n"); printf("----------------------------------------------------------------- - \n"); printf("s.n.| name | code | quantity | price| mfg.date \n"); printf("----------------------------------------------------------------- - \n"); (i = 0; < n; i++) printf("%d %-15s %-d %-5d %-5d%d / %d / %d \n", + 1, item[i].name, item[i].code, item[i].qty,item[i].price, item[i].mfg.day, item[i].mfg.month,item[i].mfg.year); printf("----------------------------------------------------------------- - \n"); }
you should provide size of buffer. example, if reading 1 char, should this:
char c; scanf_s("%c", &c, 1);
please read ref!
also, structs
nice placed before main()
. have example in mind, on basic usage of structs
.
the prototype of main should int main(void)
in case. check this: int main() vs void main() in c
in code, change this:
scanf_s("%s", item[i].name);
to this:
scanf_s("%s", item[i].name, 20);
because of this:
struct details { char name[20]; ..
do same rest..
Comments
Post a Comment