printf一个结构体里面的string出现内存泄漏,求原因
printf( "input student name\n ");
scanf( "%s ",&stdstruct[i].stdname);
printf( "input student score\n ");
scanf( "%d ",&stdstruct[i].testScore);
student是一个结构体。name是string类型,testscore是int类型。
最后输出的时候用
printf( "the name of student who get the highest score is %s\n ",&first.stdname);
printf( "Whose score is %d\n ", first.testScore);
程序可以运行,但是出现 烫烫 内存泄漏,请高手告知原因。
[解决办法]
printf( "the name of student who get the highest score is %s\n ",&first.stdname);
---
printf( "the name of student who get the highest score is %s\n ", first[i].stdname);
[解决办法]
scanf( "%s ",&stdstruct[i].stdname);
==》
scanf( "%s ",stdstruct[i].stdname);
printf( "the name of student who get the highest score is %s\n ",&first.stdname);
---
printf( "the name of student who get the highest score is %s\n ", first[i].stdname);