发现一个很奇怪的问题...
程序代码:#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <conio.h>
#include <stdlib.h>
typedef struct information
{
char name[18];
char phone[50];
}person;
int Input(person people[])
{
int count = 0;
char answer = 'n';
for(;;)
{
printf("姓名:");
gets(people[count].name);
printf("电话:");
gets(people[count++].phone);
printf("还需要输入?(y/n):");
scanf(" %c",&answer);
while(getchar() != '\n');
if(tolower(answer) == 'n')
break;
}
return count;
}
char *zhuanhuan(char *);
int main(void)
{
person people[18];
int count = 0;
char answer[18] ;
int i = 0;
char *temp = NULL;
char *temp2 = NULL;
count = Input(people);
for(;;)
{
printf("\n\n\n需要查看信息?(打入名字或者All查看全部):");
gets(answer);
if(answer[0] == 'n')
break;
if(strcmp(temp = zhuanhuan(answer), "all") == 0)
{
free(temp);
printf("\nAll the information:");
for(i=0;i<count;i++)
printf("\nname:%s\nphone:%s\n\n",people[i].name,people[i].phone);
break;
}
else
{
printf("\nt = %s\n",temp);
free(temp);/* 释放没有释放的temp */
temp = NULL;
printf("运行");
for(i=0;i<count;i++)
{
if(strcmp(temp = zhuanhuan(answer), temp2 = zhuanhuan(people[i].name)) == 0)
{
printf("\nPersonal information:\nname:%s\nphone:%s\n",people[i].name,people[i].phone);
free(temp);
free(temp2);
break;
}
free(temp);
free(temp2);
}
}
}
return 0;
}
char *zhuanhuan(char *temp)
{
char *ptemp = (char*)malloc(sizeof temp);
int i = 0;
strcpy(ptemp,temp);
for(i=0;i<(int)strlen(ptemp);i++)
ptemp[i] = tolower(ptemp[i]);
printf("p = %s\nt = %s\n",ptemp,temp);
return ptemp;
}在这里一旦输出的名字多于4个字符如"jdaa"(包括终止符)我的电脑就会出警告
但全部忽略一样可以正常运行,而且是释放temp的空间是出的警告,可在那之前专门检测过temp,里面有数据啊...只希望各位仁兄们把源代码复制一下,运行下看是不是和我一样的结果









