|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 hxliu 于 2017-7-7 17:32 编辑
结合课后习题编写笔记。
S1E2
0x00:C诡异力气,缺陷重重,却获得了巨大成功。
——Dennis Ritchie
0、C语言优势:效率高、灵活度高、可移植性高。
1、CPU是计算机的“大脑”,负责日常计算,原理上只认识0和1。
2、CPU唯一认识的语言是机器语言(机器码),由纯数字组成。
3、区别
(编译型语言)
C语言->汇编语言->机器语言->CPU执行
源代码=》编译器(编译)->机器码=>CPU(执行)
(解释型语言)
JAVA->字节码->解释器->CPU执行
源代码(转换)-》中间代码(发送)->解释器(逐句翻译)=》CPU(执行)
4、不同操作系统上C语言编译的可执行和程序格式不同,无法跨平台直接使用。例如:Linux大部分可执行文件为ELF格式,Windows大部分为PE格式。
5、解释型编程语言以不同操作系统的定制解释器作为中转,解释器提供统一入口,实现跨平台。
6、莫斯密码的原理:查表。
先和C语言打个招呼~
- #include <stdio.h>
- int main()
- {
- printf("Hello World!\n");
- return 0;
- }
复制代码
接下来是课后作业的第一个程序、以及多种注释方式
- // 统计当前目录及所有子目录下,C语言源文件的代码总行数。
- /*
- 注释1
- 注释2
- 注释3
- */
- #if 0
- 注释123456
- 注释123456
- #endif
- #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);
- int isCode(const char *filename);
- 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[MAX], target[MAX];
-
- 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[MAX];
-
- 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[MAX] = ".";
-
- printf("计算中...\n");
-
- findAllCodes(path);
- findALLDirs(path);
-
- printf("目前你总共写了 %ld 行代码!\n\n", total);
- system("pause");
-
- return 0;
- }
-
复制代码
|
评分
-
查看全部评分
|