沐清风 发表于 2021-7-24 10:28:24

{:10_266:}

zhuangzitao 发表于 2021-7-24 11:30:57

用VS code编译运行,在输出界面显示乱码怎么搞?

鲸在海澜时 发表于 2021-7-24 11:31:41

答案

卡莉丝塔 发表于 2021-7-24 11:41:36

1

Airs6 发表于 2021-7-24 11:44:28

参考答案

Gbaldr 发表于 2021-7-24 12:15:44

11111

俺想当大虾 发表于 2021-7-24 13:02:54

出错了

热心小胡 发表于 2021-7-24 13:08:06

void findALLFiles(const char *path) 这个函数没有定义啊 咋回事

PJayvyn 发表于 2021-7-24 13:09:06

{:10_257:}

鱼仔1 发表于 2021-7-24 13:15:30

1

外星人耳朵 发表于 2021-7-24 14:44:58

666

lasty 发表于 2021-7-24 14:48:16

11

吕木对 发表于 2021-7-24 15:36:16

{:5_90:}

wuli泽泽 发表于 2021-7-24 16:03:02

..

wang1086335 发表于 2021-7-24 16:07:08

ok

洁曦er 发表于 2021-7-24 16:10:10

查看答案

yyydddqqq 发表于 2021-7-24 16:26:44

1

cutar 发表于 2021-7-24 16:30:40


#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)) != -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;
      
      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;
}

zyl2 发表于 2021-7-24 16:33:09

1

笑靥喵 发表于 2021-7-24 16:45:09

1
页: 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 [1272] 1273 1274 1275 1276 1277 1278 1279 1280 1281
查看完整版本: S1E2:第一个程序 | 课后测试题及答案