首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

printf一个结构体里面的string出现内存泄漏,求原因解决方法

2012-03-08 
printf一个结构体里面的string出现内存泄漏,求原因printf( inputstudentname\n )scanf( %s ,&stdstru

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);

热点排行