zhijie 发表于 2020-9-19 21:13:44

为什么我编辑打开了是204行代码的?

番茄也想变成马 发表于 2020-9-19 21:25:35

不知道怎么进入编程界面啊

zhijie 发表于 2020-9-19 21:26:35

为什么我运行出来时204行代码的{:10_243:}

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

Cooper鱼 发表于 2020-9-19 21:28:34

哈哈哈

707337837 发表于 2020-9-19 21:41:48

谢谢

豪HG歌 发表于 2020-9-19 21:44:14

我复制的代码不对{:5_90:}

张衡其人 发表于 2020-9-19 21:51:47

j

XKnight 发表于 2020-9-19 21:53:48

哈哈

Maxcc1874 发表于 2020-9-19 22:11:33

{:5_110:}

Hins轩 发表于 2020-9-19 22:53:49

我会好好学的

满天星wu 发表于 2020-9-20 00:18:06

查看参考答案

Linler 发表于 2020-9-20 09:33:47

初学者,连英文都不识几个,我有机会吗

UnaPeng 发表于 2020-9-20 10:41:50

0. 为什么我们说计算机其实是“二傻子”?
它只懂德二进制的0&1

1. CPU 唯一认识的语言是什么语言?
机器语言

2. C 语言编写的源代码转换为汇编语言的过程叫什么?
编译

3. 编译型语言和解释型语言的本质区别是什么?
源代码最终编译成机器语言,也就是我们所说的可执行文件,从此 CPU 就可以直接执行;解释型语言不直接编译成机器码,而是将源码转换成中间代码,然后发送给解释器,由解释器逐句翻译给 CPU 来执行

4. 在 Linux 系统上用 C 语言编译的可执行程序,是否能在 Windows 系统上执行?
可以,80% 的代码是公共的,可能需要稍加改动

5. 解释型编程语言是如何实现跨平台的?
解释型语言不直接编译成机器码,而是将源码转换成中间代码,然后发送给解释器,由解释器逐句翻译给 CPU 来执行

6. 莫斯密码的原理其实是什么?
查表

7. 视频中小甲鱼“故弄玄虚”的那段密文还原后是什么内容(中文)?
亲们,趁敌人吃饭时发动进攻


kimio 发表于 2020-9-20 10:43:51

冲冲冲

Tsinghua丶 发表于 2020-9-20 10:44:11

感谢小甲鱼

Hipmione 发表于 2020-9-20 10:57:14

,

tging 发表于 2020-9-20 11:32:26

d

Cayexin 发表于 2020-9-20 11:56:28

答案

15766254947 发表于 2020-9-20 11:58:55

{:10_247:}{:10_260:}有点难

叫我阿良 发表于 2020-9-20 12:05:26

很有用呀 谢谢up主的分享 视频很棒 加油呀
页: 851 852 853 854 855 856 857 858 859 860 [861] 862 863 864 865 866 867 868 869 870
查看完整版本: S1E2:第一个程序 | 课后测试题及答案