Minus1 发表于 2021-9-18 18:59:42

还是不太清楚虚拟机里面该怎么运行我抄下来的代码啊呜呜呜

马马是马马 发表于 2021-9-18 19:01:59

计算机只懂的0和1
机器语言
编译
解释型语言需要一个解释的过程,要时间更长
用不同的解释器
对应代码表翻译

开始入门 发表于 2021-9-18 20:01:58

看看答案

junran 发表于 2021-9-18 21:15:29

1

北念辰 发表于 2021-9-18 21:17:16

打卡第一天

2679621537 发表于 2021-9-18 21:57:50

ok

lswlla 发表于 2021-9-18 22:34:43

1

lswlla 发表于 2021-9-18 22:36:53

1

CYLLd 发表于 2021-9-18 22:50:17

那个程序怎么用啊 是放到同一个目录吗

迎我以诗 发表于 2021-9-19 01:26:22

亲爱的鱼鱼每天都要加油学习哦

KikiCheung 发表于 2021-9-19 02:39:21

S1E2

llovely 发表于 2021-9-19 09:26:38

回复

张家骏猛1 发表于 2021-9-19 09:28:52

?

wly201288 发表于 2021-9-19 09:44:50

1

Avery00117 发表于 2021-9-19 10:15:41

1

黄国锐 发表于 2021-9-19 10:26:59


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

Luckyyyyy 发表于 2021-9-19 10:43:13

1

拉格朗日的冲动 发表于 2021-9-19 11:05:25

这Windows代码,复制过去是0行.

675500497 发表于 2021-9-19 11:13:50

来看答案了

15620117641 发表于 2021-9-19 11:34:47

1
页: 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 [1376] 1377 1378 1379 1380 1381 1382 1383 1384 1385
查看完整版本: S1E2:第一个程序 | 课后测试题及答案