Tablica struktur ( napis)

0

Cześć. Nie mogę nigdzie znaleźć odpowiedzi więc pisze.... Nie wiem jak wprowadzic napis(wyraz) za pomocą funkcji scanf_s()... Pojawia mi sie bład o 2 argumentach... Nie rozumiem... Sprawa wygląda tak:

#include<stdio.h>
#include <string.h>
#define N 5
struct dane
{
	char napis[20];
	int liczba;
};

int main()
{
	struct dane tab[N];

	for (int i = 0; i < N; i++)
	{
		printf("Prosze podac %d wyraz :", i+1);
		gets(tab[i].napis);
		putchar('/n');
		printf("Prosze podac %d liczbe :", i+1);
		while (scanf_s("%d", &tab[i].liczba) != 1 || getchar() != '\n')
		{
			printf("Podales bledne dane popraw... :");
			while (getchar() != '\n')
				;
		}
		putchar('\n\n');
	}


		return 0;
}
4

https://msdn.microsoft.com/en-us/library/w40768et.aspx

Unlike scanf and wscanf, scanf_s and wscanf_s require the buffer size to be specified for all input parameters of type c, C, s, S, or string control sets that are enclosed in []. The buffer size in characters is passed as an additional parameter immediately following the pointer to the buffer or variable. For example, if you are reading a string, the buffer size for that string is passed as follows:

char s[10];
scanf_s("%9s", s, (unsigned)_countof(s)); // buffer size is 10, width specification is 9

1 użytkowników online, w tym zalogowanych: 0, gości: 1