Here is my code:
#include <stdio.h>
#include <iostream>
#include <conio.h>
char filename[100];
FILE *stream, *stream2;
char s[20];
struct date
{
int day, month, year;
};
struct employee
{
int ID;
char name[100];
date birthdate;
char address[20];
char rank[20];
int money;
};
void main()
{
errno_t err;
// Open for read (will fail if file "crt_fopen_s.c" does not exist)
// Open for write
err = fopen_s(&stream2, "C:/Users/Van/Desktop/LAALAL/fool.txt", "w+");
if (err == 0)
{
employee nv;
std::cout << "\nInput information of an employee:\n";
std::cout << "\tInput ID : ";
std::cin >> nv.ID;
std::cin.sync();
std::cout << "\tInput name : ";
std::cin.clear();
gets_s(s);
gets_s(nv.name);
std::cout << "\tInput birthdate (Day Month Year ) : ";
std::cin >> nv.birthdate.day >> nv.birthdate.month >> nv.birthdate.year;
std::cout << "\tInput address: ";
std::cin.clear();
gets_s(s);
gets_s(nv.address);
std::cout << "\tInput rank : ";
std::cin.clear();
gets_s(s);
gets_s(nv.rank);
std::cout << "\tMoney : ";
std::cin >> nv.money;
std::cin.sync();
std::fwrite(&nv, sizeof(nv), 1, stream2);
std::fclose(stream2);
}
}
Well I don't have any problem with the code, but when I input my information, I cant read the output in the file. Here is the picture of my output:
What is my problem? Thanks in advance for your time!