3787| 5
|
[已解决]为什么fgets函数和gets函数会使循环终止? |
10鱼币
最佳答案#include
#include
#define MAX 1024
int main()
{
int i;
const int num = 4;
char *pnames[3];
for(i = 0; i < num; i++)
{
pnames= malloc(MAX);
fgets(pnames, MAX, stdin);
printf("i = %d, num = %d\n", i, num);
if(i == num-1)
{
printf("队伍名称已录入完毕,正在计算比赛安排...\n");
}
}
return 0;
}
情况不确定,但是num如果不用修改的话尽量用const定义 ...
| ||
小甲鱼最新课程 -> https://ilovefishc.com
|
||
| ||
小甲鱼最新课程 -> https://ilovefishc.com
|
||
| ||
小甲鱼最新课程 -> https://ilovefishc.com
|
||
| ||
小甲鱼最新课程 -> https://ilovefishc.com
|
||
| ||
小甲鱼最新课程 -> https://ilovefishc.com
|
||
| ||
小甲鱼最新课程 -> https://ilovefishc.com
|
||
小黑屋|手机版|Archiver|鱼C工作室
( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)
GMT+8, 2025-6-17 13:49
Powered by Discuz! X3.4
© 2001-2023 Discuz! Team.