鱼C论坛

 找回密码
 立即注册
查看: 2903|回复: 6

不知道哪里有问题,第一天大佬救命

[复制链接]
发表于 2022-9-7 02:04:23 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x

#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 findA11Codes(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[MAX], target[MAX];
       
        strcpy(thePath, path);
        if((handle = _findfirst(strcat(thePath, "/*.c"), &fa)) != -1L)
        {
                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[MAX];
       
        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);
                         findA11Codes(thePath);
                         findALLDirs(thePath);
                 }
         }while (_findnext(handle, &fa) == 0);
         
         _findclose(handle);
}

int main()
{
        char path[MAX] = ".";
       
        printf("计算中...\n" );
       
        findA11Codes(path);
        findALLDirs(path);
       
        printf("目前你总共写了 %1d 行代码! \n\n", total);
        system("pause");
       
        return 0;
}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2022-9-7 02:15:51 | 显示全部楼层
认真一点,因为一个字符也不能错
findA11Codes

你能分清楚数字1和字母l吗?
与此类似的 0 O o ! 1 i l ` ' , .
这些都是不同的字符
代码中肯定还有很多这类写错字符的情况
你说你不认真写错了字符能怎么办?
要真的想学编程,那就请认真一点吧
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-9-7 02:19:12 | 显示全部楼层
一个字符也不能错,你这错了几个字符了,至少也两个了,这是至少
就在此时,我又发现了一个
         printf("目前你总共写了 %1d 行代码! \n\n", total);

已经至少错了3个字符了,错一个都不行,你已经错了至少3个了,程序当然是不能运行了
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-9-7 02:20:04 | 显示全部楼层
我就不一个一个给你数了,错的肯定不止这3个字符
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-9-7 02:22:59 | 显示全部楼层
自己认真一点,一个字符一个字符的检查吧
顺便数一数错了多少个字符
如果第1次错了100个字符,第2次错了90个字符
这就是进步,有进步就是好的,慢慢来吧
请记住, 要真的想学编程,那就请认真一点吧
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-9-7 02:27:20 | 显示全部楼层
我简单的看了一下,好像是错了11个字符
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-9-7 02:36:23 | 显示全部楼层
删除了一些不影响错误的字符,一共错了12个字符
1.png
2.png
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-6-2 14:31

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表