简体   繁体   中英

I Can't Opening A Txt File In Program Of C Language

I have my code here. Every time I try to open a text file it's giving me an error message.

Person temp;
FILE *in, *out;
in = fopen_s(&in,"the_first.txt","rt");
if (!in)
   Error_Msg("Error message");
fscanf_s(in,"%d",&temp.ID);
fclose(in);
_getch();
return 0;

What do I need to change in my code to make it work?

Person temp;
FILE *in, *out;
errno_t err;

err = fopen_s(&in,"the_first.txt","rt"); 
if (err)
{
   Error_Msg("Error message");
}
else
{
    fscanf_s(in,"%d",&temp.ID);
    fclose(in);
    _getch();
}
return 0;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM