这个代码为什么输出不了badapple
文件路径没问题,改了一下午了
应该有一个关于null 的if判定不对
但不知道怎么改 求求拉


#include <stdio.h>
#include <stdlib.h>
#include <Windows.h>
#include <string.h>
#include<time.h>
#pragma warning(disable : 3282)
static void SetPos(int x, int y)
{
COORD point = { 150, 150 }; //光标要设置的位置x,y
HANDLE HOutput = GetStdHandle(STD_OUTPUT_HANDLE); //使用GetStdHandle(STD_OUTPUT_HANDLE)来获取标准输出的句柄
SetConsoleCursorPosition(HOutput, point); //设置光标位置
}
int main()
{
FILE* fp;
char buf[150], add[60], ai[5];
int i=1,delay=33;
clock_t stime = 0, ftime = 0;
stime = clock();
while (i<=3282)
{
if (i % 30 == 0)
{
delay = 43;
}
else
{
delay = 33;
}
strcpy(add, "E:\\c语言显示\\bad apple\\ask码\\a(");
sprintf(ai, "%d", i);
strcat(add, ai);
strcat(add, ").txt");
// 名字修改
ftime = clock();
if (ftime - stime >= delay)
{
fp = fopen(add, "r");//打印文本
if (NULL == fp){}
else
{
while (fgets(buf, 150, fp))
{
printf("%s", buf);
}
fclose(fp);
SetPos(0, 0);
i++;
stime += delay;
} } }
return 0;}
文件路径没问题,改了一下午了
应该有一个关于null 的if判定不对
但不知道怎么改 求求拉



#include <stdio.h>
#include <stdlib.h>
#include <Windows.h>
#include <string.h>
#include<time.h>
#pragma warning(disable : 3282)
static void SetPos(int x, int y)
{
COORD point = { 150, 150 }; //光标要设置的位置x,y
HANDLE HOutput = GetStdHandle(STD_OUTPUT_HANDLE); //使用GetStdHandle(STD_OUTPUT_HANDLE)来获取标准输出的句柄
SetConsoleCursorPosition(HOutput, point); //设置光标位置
}
int main()
{
FILE* fp;
char buf[150], add[60], ai[5];
int i=1,delay=33;
clock_t stime = 0, ftime = 0;
stime = clock();
while (i<=3282)
{
if (i % 30 == 0)
{
delay = 43;
}
else
{
delay = 33;
}
strcpy(add, "E:\\c语言显示\\bad apple\\ask码\\a(");
sprintf(ai, "%d", i);
strcat(add, ai);
strcat(add, ").txt");
// 名字修改
ftime = clock();
if (ftime - stime >= delay)
{
fp = fopen(add, "r");//打印文本
if (NULL == fp){}
else
{
while (fgets(buf, 150, fp))
{
printf("%s", buf);
}
fclose(fp);
SetPos(0, 0);
i++;
stime += delay;
} } }
return 0;}