Как вывести элементы структуры в Си?
как вывести элементы структуры в Си ,в C++ с помощью cout всё работает, в Си с printf что-то не получается, может мой синтаксис не верен.
Вот часть кода, с cout с++, оно работает.
struct game
{
char title[100];
char players[100];
char platform[100];
char genre[100];
char developer[100];
int year;
unsigned int min_cpu;
unsigned int min_ram;
unsigned int min_hdd;
void getInfo()
{
cout << " title: " << title << endl;
cout << " players: " << players << endl;
cout << " platform:" << platform << endl;
cout << " genre: " << genre << endl;
cout << " developer: " << developer << endl;
cout << " year: " << year << endl;
cout << " min_cpu: " << min_cpu << endl;
cout << " min_ram: " << min_ram << endl;
cout << " min_hdd: " << min_hdd << endl;
Ответы (1 шт):
Автор решения: Harry
→ Ссылка
Правильно пишите форматную строку, и пребудет с вами корректный вывод...
cout << " title: " << title << endl;
printf("%s\n",title);
cout << " year: " << year << endl;
printf("%d\n",year);
cout << " min_cpu: " << min_cpu << endl;
printf("%u\n",min_cpu);