ajut 2023-02-27 12:23 采纳率: 100%
浏览 41
已结题

vscode报错,不知道怎么解决

源代码如下


#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[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);
                    findAllCodes(thePath);
                    findALLDirs(thePath);
                }
    }while (_findnext(handle,&fa)==0);

        _findclose(handle);
}

int main()
{
        char path[MAX]=".";

        printf("计算中...\n");

        findAllCodes(path);
        findALLDirs(path);

        printf("目前你总共写了%1d行代码!\n\n",total);
        system("pause");

        return 0;

}

img

  • 写回答

2条回答 默认 最新

  • 浪客 2023-02-27 12:42
    关注

    2个handle的类型改一下。
    intptr_t handle; // long handle;

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 3月7日
  • 已采纳回答 2月27日
  • 创建了问题 2月27日

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度