LY2141902487 发表于 2021-7-22 16:42:48

1

孔雀胆 发表于 2021-7-22 17:16:21

S1E2:第一个程序 | 课后测试题及答案

smilies

决心年入百万 发表于 2021-7-22 18:26:04

给我康康

快乐哒小胖墩 发表于 2021-7-22 20:48:53

1.机械语言
2.编译
3.过程步骤
4.可以

吊布兰度 发表于 2021-7-22 20:53:47

核对答案

六五与六七 发表于 2021-7-22 21:12:10

{:10_327:}

屿龍 发表于 2021-7-22 22:55:49

1

小小灰熊 发表于 2021-7-23 00:06:25

1

Bnrgrl 发表于 2021-7-23 01:03:52


#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-7-23 02:59:33

我裂开了

猪肉超人 发表于 2021-7-23 03:33:47

请教老师,我打完代码出现了crt secure no warnings错误,然后源文件开头添加了#define _CRT_SECURE_NO_WARNINGS后运行出来结果是0,复制了您的代码后输出结果也是0,请问是为什么捏

1980307352 发表于 2021-7-23 08:02:14

机器语言

摄影艺术 发表于 2021-7-23 10:14:03

s1ed

雨中漫步~ 发表于 2021-7-23 10:42:36

0. 计算机无法直接对人的指令作出反应
1. 机器语言
2. 编译
3. 是否直接将语言编译成机器码
4. 不一定
5. 由不同的解释器将编译成的字节码解释给计算机执行
6. 编码和解码
7. WTF?

炎大刀 发表于 2021-7-23 10:52:49

123

ktyaixuexi 发表于 2021-7-23 10:55:30

查看

hardenFMVP 发表于 2021-7-23 11:48:08

答案

hukailun2 发表于 2021-7-23 11:49:45

答案

dongdong6 发表于 2021-7-23 13:33:07

1457130087 发表于 2021-7-23 13:56:59

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