cyk哦 发表于 2022-9-28 18:21:22


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

Viggo7 发表于 2022-9-28 18:40:13

一定要坚持下去呀

一拳锤石你die 发表于 2022-9-28 19:13:25

1

伊恩恩 发表于 2022-9-28 19:50:33


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

Khayal 发表于 2022-9-28 20:26:53

开始学c啦

kangyefei 发表于 2022-9-28 20:41:23

答案

mzy6 发表于 2022-9-28 21:17:18

第一个程序

不要懒惰 发表于 2022-9-28 21:21:56

0, 计算机只认识0和1两个数
1, 汇编语言
2, 编译
3, 编译是直接转换为汇编,解释还需要多一步
4, 不一定,有一些数据库略有差别,需要再次调整
5,运用同一个数据库
6, 编译
7,没试

动手
我打完了,107条代码

尚巾锦旗 发表于 2022-9-28 23:07:47

1

我是小小小乌龟 发表于 2022-9-28 23:13:28

1

高肆玖捌伍 发表于 2022-9-28 23:50:06

新手菜鸟想问一下为啥行数记录程序不能只能到102,也就是算不上其他的源文件。

aka水 发表于 2022-9-29 00:14:42

回复

徐牧北 发表于 2022-9-29 09:05:04

1

英明神武李瓜皮 发表于 2022-9-29 09:14:29

答案

SFYWR 发表于 2022-9-29 09:19:14

S1E2

欣悦宝贝 发表于 2022-9-29 09:54:19

0.只能读懂二进制,需要人交给他怎么做,不会自己运行
1.二进制
2.编译
3.是否可移植
4.不能
5.
6.对照一个表完成翻译
7.亲们趁敌人吃饭发动进攻

wgszl 发表于 2022-9-29 11:10:32

1

1223723105 发表于 2022-9-29 11:16:51

1.计算机只认识零和一
2只认识机械语言
3.编译
4.解释型语言只生成对应文件还需要通过解释器来进行翻译,翻译后才可以被计算机识别并运行。而编译型语言会生成可执行文件直接可以被计算机识别并运行
5.不能
6.通过不同的解释器?
7.摩斯密码是通过不同的组合来表示相对应的字母
8.pass

yanque 发表于 2022-9-29 11:44:02

kanwan

xzy. 发表于 2022-9-29 13:48:21

HUIFU]
页: 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 [1757] 1758 1759 1760 1761 1762 1763 1764 1765 1766
查看完整版本: S1E2:第一个程序 | 课后测试题及答案