[HUST CSE] fix fgets_tc.c (#7503)

这个文件里存在使用fopen函数后没有关闭文件fclose的问题,而且stream=NULL时是不需要fclose的
This commit is contained in:
chiehwarm 2023-05-15 11:51:30 +08:00 committed by GitHub
parent eb08036537
commit b1415c4fc8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 1 deletions

View File

@ -19,15 +19,21 @@ static int fgets_entry(void)
fclose(stream);
stream = fopen("fopen_file.txt","r");
if (stream == NULL)
{
perror("fopen fail");
ret = -1;
goto __exit;
}
fgets(gets, sizeof(gets), stream);
if(strcmp(gets, data))
{
ret = -1;
}
fclose(stream);
__exit:
fclose(stream);
return ret;
}