yueliang78105 发表于 2021-12-5 15:34:07

100行

LvemiL 发表于 2021-12-5 15:52:35

1

变强很难吗? 发表于 2021-12-5 16:41:48

0?

鬼羡仙 发表于 2021-12-5 16:42:32

答案

变强很难吗? 发表于 2021-12-5 16:48:05

为什么我在mac 上编译后的结果是0 呢?
开始以为是自己抄错了,但是直接复制过去的代码编译后的结果也还是0

blackjack2 发表于 2021-12-5 21:24:43

回复

zhuizhui666 发表于 2021-12-5 21:41:09

为啥可以中文在前面输入

2564420080 发表于 2021-12-5 23:42:48


#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-12-5 23:48:40

Powered by

jtyydgsj 发表于 2021-12-6 08:44:03

1

陈eleven 发表于 2021-12-6 09:10:58

1

陈eleven 发表于 2021-12-6 09:16:16

为什么我的windows系统显示的是写了0行代码

hly6869 发表于 2021-12-6 11:06:29

11111

学C小林 发表于 2021-12-6 12:18:43

0.因为他是二进制的,只懂0和1
1.机器语言
2.解码
3.能否直接执行
4.可以
5.通过解释器
6.查找指令表
7.亲们趁敌人吃饭时发动进攻

FangSC 发表于 2021-12-6 12:30:52

1

Ldxuec 发表于 2021-12-6 13:07:15

Powered by bbs.fishc.com

clearlove7x 发表于 2021-12-6 13:39:08

1

moonpig 发表于 2021-12-6 14:01:55

1

Genist 发表于 2021-12-6 14:47:29

1

sun.prc 发表于 2021-12-6 14:48:13

az
不是吧
页: 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 [1480] 1481 1482 1483 1484 1485 1486 1487 1488 1489
查看完整版本: S1E2:第一个程序 | 课后测试题及答案