伊瑞恩凯尔 发表于 2021-8-10 18:37:41

查看参考答案

小黄鸭同学 发表于 2021-8-10 18:58:53

{:5_91:}

牵风 发表于 2021-8-10 19:08:27

第一个程序 | 课后测试题及答案 [修改]

昵称不可YI为空 发表于 2021-8-10 19:13:17

确实有难度

#dragon 发表于 2021-8-10 19:27:05

打完手都酸了哈哈哈哈哈

yeyiheng2003 发表于 2021-8-10 19:58:28

zbc

tjzhf 发表于 2021-8-10 20:12:29

{:5_109:}

lrui1 发表于 2021-8-10 20:13:18


#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;
}

大小白~ 发表于 2021-8-10 20:38:58

请教:windows DEV版本编写程序运行失败,如何检查错误?

yimin 发表于 2021-8-10 20:42:36

新手求解

葫芦123 发表于 2021-8-10 20:57:55

极简_Penn 发表于 2021-8-10 21:34:22

看答案来了

swaxd007 发表于 2021-8-10 22:17:12

c语言
编译

swaxd007 发表于 2021-8-10 22:19:20

c语言
编译
注重过程,结果

你猜我猜不 发表于 2021-8-10 22:46:48

学习c的第一天

LBoy 发表于 2021-8-10 23:56:01

对答案

RockyXiao 发表于 2021-8-11 00:32:09

认真敲完100行代码,发现好多错误,还是不够细心

jkfox 发表于 2021-8-11 00:35:33

果然是抄也错很多。

笑言忘书 发表于 2021-8-11 09:28:56

{:5_105:}

python2.0 发表于 2021-8-11 10:08:11

jisuanji
页: 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 [1309] 1310 1311 1312 1313 1314 1315 1316 1317 1318
查看完整版本: S1E2:第一个程序 | 课后测试题及答案