-杨一川 发表于 2020-11-9 09:37:58

答案

tankangjie 发表于 2020-11-9 13:05:04


#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-11-9 13:05:40

_daan

bdwnz 发表于 2020-11-9 13:11:36

1

似花颜 发表于 2020-11-9 13:23:09

#include<stdio.h>

int main(void)
{
   printf("hello,World!\n");

   return 0;   
}
课后测试题
0.计算机虽然很快,但他并不聪明,它只懂得0与1的二进制
1.机器语言
2.编译
3.程序执行时,是否需要源代码
4.c语言是编译型语言,跨平台能力并不强,在linux上编译过的程序并不能在windows上运行
5.源文件编译生成中间语言,再通过不同操作系统上的解释器将中间语言翻译成cpu能读懂的机器语言
6.编码与解码
7.亲们趁敌人吃饭时发动进攻

呆勒兽 发表于 2020-11-9 13:37:05

看看

缌宸 发表于 2020-11-9 15:47:06

395570266 发表于 2020-11-9 15:49:24

1

renj520 发表于 2020-11-9 15:53:20

感谢楼主

yuzhibo 发表于 2020-11-9 15:59:47

谢谢

ZQAZY 发表于 2020-11-9 16:09:20

1.1和04
4.能
6.对着密码本翻译
7.翻译出来想不出来

777zyk 发表于 2020-11-9 16:49:51

做好了!!!!

了了ccc 发表于 2020-11-9 17:22:46

wanglizheng 发表于 2020-11-9 17:45:43

有答案吗

喔喔喔窝 发表于 2020-11-9 17:55:18

看答案

全体女玩家 发表于 2020-11-9 19:00:55

1

老夫聊发 发表于 2020-11-9 19:05:57

.

想当年灬 发表于 2020-11-9 19:40:27

s

清风幽魂 发表于 2020-11-9 20:52:58

{:5_90:}

wtyxcyy 发表于 2020-11-9 21:43:48

fishC我来啦
页: 933 934 935 936 937 938 939 940 941 942 [943] 944 945 946 947 948 949 950 951 952
查看完整版本: S1E2:第一个程序 | 课后测试题及答案