为什么会这样
在学第一个课,第一个程序,课后作业做出来确实这样,有大佬问问这是为什么吗? 哈哈,别着急,我来帮你解答。可能有很多原因会导致这种情况。首先,你可以告诉我具体的问题和错误,这样我才能更好地帮助你。通常情况下,第一个程序会比较简单,例如输出"Hello, World!"。如果你遇到了问题,可能是以下几个方面出了点小问题:
1. **语法错误**:请检查你的代码,看看是否有遗漏的括号、分号或其他标点符号等。这些错误可能会导致程序无法正常运行。
2. **命名错误**:你的变量名或函数名是否拼写正确?在编程中,大小写是敏感的。确保你在使用变量和函数时使用了正确的名称。
3. **逻辑错误**:程序的逻辑是否正确?有时候我们的思路可能有问题,导致程序输出的结果不是我们期望的。你可以仔细检查你的代码,看看是否有逻辑错误。
4. **编译错误**:有时候,编译器会给出错误的信息或者没有给出任何提示。这时候我们可以尝试重新编译或者重新打开编辑器。
如果你能提供具体的错误信息或者代码,我会更加详细地回答你的问题并给出相应的解决方案。总之,编程是一门需要耐心和实践的技能,一点点的积累和经验,你一定可以掌握!加油!
以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。 至少,你得贴出你的代码,注意,一定要贴成文本,不要贴成图片。 哥们,你要说个啥? jackz007 发表于 2024-3-15 08:08
至少,你得贴出你的代码,注意,一定要贴成文本,不要贴成图片。
是的,我也发现了AI不看图片的,只看代码。 jackz007 发表于 2024-3-15 08:08
至少,你得贴出你的代码,注意,一定要贴成文本,不要贴成图片。
并且 ,你一定要把自己的问题描述尽量简化,不然,Ai会把你绕晕。。。。 本帖最后由 zhangjinxuan 于 2024-3-15 08:57 编辑
你搜索到 fopen 这个地方,把 .第一个程序.c 改成 .\\第一个程序.c
如果你能保证你的其他地方被有写错的话,就是你的统计代码行的程序没有找到你的想要统计代码行的文件,请检查被统计的代码的文件是否和你的“课后作业”在同一个目录下或者确保路径正确。 清風 发表于 2024-3-15 08:46
并且 ,你一定要把自己的问题描述尽量简化,不然,Ai会把你绕晕。。。。
搞清楚,在鱼C论坛,只有 FishC 才是 AI。 jackz007 发表于 2024-3-15 10:32
搞清楚,在鱼C论坛,只有 FishC 才是 AI。
我说的AI就是FishC, 怎么了?
#include <io.h>
#include <direct.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 256
long total;
int countLines(const char *filename);
void findAllCodes(const char *path);
void findALLFiles(const char *path);
int countLines(const char *filename)
{
FILE *fp;
int count = 0;
int temp;
if((fp =fopen(filename,"r")) == NULL)
{
fprintf(stderr, "Can not open the file: %s\n", filename);
return 0;
}
while ((temp == fgetc(fp)) != EOF)
{
if(temp =='\n')
{
count++;
}
}
fclose(fp);
return count;
}
void findAllCodes(const char *path)
{
struct _finddata_t fa;
long handle;
char thePath,target;
strcpy(thePath, path);
if((handle = _findfirst(strcat(thePath, "/*.c"),&fa)) != -1)
{
do
{
sprintf(target, "%s%s", path, fa.name);
total += countLines(target);
}while (_findnext(handle, &fa) == 0);
}
_findclose(handle);
}
void findALLDirs(const char *path)
{
struct _finddata_t fa;
long handle;
char thePath;
strcpy(thePath, path);
if((handle = _findfirst(strcat(thePath, "/*"), &fa)) == -1L)
{
fprintf(stderr, "The path %s is wrong!\n",path);
return;
}
do
{
if (!strcmp(fa.name, ".") || !strcmp(fa.name, ".."))
continue;
if( fa.attrib == _A_SUBDIR)
{
sprintf(thePath, "%s/%s", path, fa.name);
findAllCodes(thePath);
findALLDirs(thePath);
}
}while (_findnext(handle, &fa) == 0);
_findclose(handle);
}
int main()
{
char path = ".";
printf("计算中...\n");
findAllCodes(path);
findALLDirs(path);
printf("目前你总共写了 %ld 行代码! \n\n", total);
system("pause");
return 0;
} 显示0行
保存路径应该没有错,按着视频操作的
页:
[1]