liuqiangabc 发表于 2020-3-7 18:48:03

1

1332655856 发表于 2020-3-7 19:30:21


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

幸运巴别塔 发表于 2020-3-7 20:23:58

11

切手厨师 发表于 2020-3-7 20:37:37

来看答案啦

对牛弹琴的三高C 发表于 2020-3-7 21:08:16

测试题:

0.答:因为计算机只能识别“0”和“1”这种机器语言;
1.答:机器语言;
2.答:编译;
3.答:编译型语言是运行前只需要编译一次就行了,解释型语言是每次运行前都需要进行编译;
4.答:可以
5.答:解释型语言不直接编译成机器码,而是将源码转换成中间代码,然后发送给解释器,由解释器逐句翻译给 CPU 来执行;
6.答:机器语言;
7.亲们趁敌人吃饭时发动进攻(qin men chen di ren chi fan shi fa dong jin gong)搜狗拼音打出来就是这样的了。。。。。。。。。。
等级太低上传不了图片,Ctrl+c复制源代码编译运行后显示写了211行代码,点击源代码最后面的“复制代码”编译运行后显示写了211行代码。

自己手动写上去的代码,在编译运行的时候出错了错误显示“undefined reference to 'strcov'”,搞了半天还是没有编译运行出来,我受不了了,第一次写代码就出问题了,还是一个字母一个字母对着抄下来的,唉。。。。。。
                                          

                      有哪位知道怎么解决的小哥看到了,希望能帮忙解决一下,感谢了!!!

对牛弹琴的三高C 发表于 2020-3-7 21:14:07

第一次抄错了,搞了半天没有搞好,先平复下情绪,等会再抄一次试试

阿小飞 发表于 2020-3-7 21:37:38

Yl957405782 发表于 2020-3-7 21:56:21

大佬辛苦了

学编程的小飞鱼 发表于 2020-3-7 22:29:51

因为CPU只能识别0和1

hepengwudi 发表于 2020-3-7 22:51:35

7

Draem 发表于 2020-3-7 22:58:10


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

雨戛花花 发表于 2020-3-8 05:28:43

谢谢谢谢

最早的早安 发表于 2020-3-8 08:58:36

已做

对牛弹琴的三高C 发表于 2020-3-8 09:38:14

昨天写的直接编译不出来,今天早上起来用了一个小时抄写和查错修改,最有编译运行了,显示写了313代码。。。。。。。      要继续努力了

啊川 发表于 2020-3-8 10:57:20

0.

whitpseal 发表于 2020-3-8 11:13:25

{:10_245:}

15338731319 发表于 2020-3-8 12:37:47

看看

geen 发表于 2020-3-8 12:49:29

本帖最后由 geen 于 2020-3-8 12:58 编辑


测试题:
0. 因为计算机只认识0和1;
1.机器语言;
2.编译;
3.说不出来;
4.不能直接运行,需要对源代码进行部分修改后才可以运行;
5.把不同平台的源代码解释成字符码,再用解释器解释成机器码;
6.使用具有映射关系的表对明文进行编码加密,只有拥有加密表的接收方才能解码成明文。
7.QINMEN
CHEND
IRENC
HIFP(AN)(把AN解码成了P)
SHIF
ADONG
JING(O)(漏了O)
NG

阿苒 发表于 2020-3-8 13:02:10

1

土星大叔 发表于 2020-3-8 13:21:35

瞅一瞅
页: 605 606 607 608 609 610 611 612 613 614 [615] 616 617 618 619 620 621 622 623 624
查看完整版本: S1E2:第一个程序 | 课后测试题及答案