道三清 发表于 2021-1-21 21:44:47

回复

南柯长梦 发表于 2021-1-21 22:16:00

wiiiiiith

请叫我C神 发表于 2021-1-21 22:28:15

hhh

一曲琵琶月色寒 发表于 2021-1-21 23:10:45

1

咿呀嘿 发表于 2021-1-21 23:46:34

{:5_110:}

画船听雨眠i 发表于 2021-1-22 00:21:48

1

AuroraT 发表于 2021-1-22 10:36:07

1

我原地乱鲨 发表于 2021-1-22 11:02:51

1

菜刀皇帝 发表于 2021-1-22 11:16:51


呀樱花 发表于 2021-1-22 11:46:20


#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-1-22 12:02:02

答案

106065026 发表于 2021-1-22 12:05:12


嘿,亲爱的鱼油,每天都要过得开心哦^_^

gyf196363132 发表于 2021-1-22 12:30:05

9666666666666666

靠海喜欢浪 发表于 2021-1-22 12:48:43

q8712175 发表于 2021-1-22 13:38:38

1

HWant 发表于 2021-1-22 14:01:33

0.计算机只看得懂0和1
1.机器语言
2.编译
3.有没有编译成机器码
4.可以
5.解释器
6.查表
7.亲们,趁敌人吃饭时发动进攻

yitingqiu 发表于 2021-1-22 14:05:52

主题

hmy20020903 发表于 2021-1-22 15:51:54

抄完收工

178 发表于 2021-1-22 15:58:11

{:7_131:}

巧生 发表于 2021-1-22 16:16:47

感谢楼主无私奉献!
页: 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 [1026] 1027 1028 1029 1030 1031 1032 1033 1034 1035
查看完整版本: S1E2:第一个程序 | 课后测试题及答案