C语言开发工具Dev-C++
,CLion
和 Cygwin
Cygwin
和其他两个工具有一个即可, Cygwin
主要是为了使用纯命令测试原理,
Dev-C++
和CLion
工具自带C
开发环境
环境搭建
使用Cygwin
只是为了测试一下纯命令开发C
语言
windows
系统使用Cygwin
搭建C
语言开发环境
下载Cygwin
安装,选择镜像http://mirrors.163.com
,更多镜像参考https://cygwin.com/mirrors.html
select Packages
中选择gcc-core
、gcc-g++
、make
、gdb
、binutils
五个包下载(注意在右侧三角选择版本)
配置环境变量,让cmd
中可以使用
把安装好的的Cygwin
配置环境变量
环境变量 C:\cygwin64\bin
和 C:\cygwin64\sbin
安装结束
第一个程序
把下面内容写入到fei.c
文件中
1 2 3 4 5 6 7 8 9
| #include <stdio.h> int main() { printf("这是我的第一个C程序 \r\n"); printf("Hello, World! \n"); return 0; }
|
1 2 3 4 5 6 7 8 9
| #include <stdio.h> #include <process.h>
int main() { system("chcp 65001"); printf("Hello, World!\n"); printf("大ddd飞!\n"); return 0; }
|
执行命令
1 2 3 4
| gcc -o fei.out fei.c
fei.out 回车
|

用工具创建程序
使用Dev-C++
和CLion
创建Console Application
应用即可执行
入门dem01
成绩评估
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| #include <stdio.h>
int main() { system("chcp 65001"); int score; printf("请输入你的成绩(0-100):"); scanf("%d:", &score);
if (score >= 90) { printf("优秀,你真棒\n"); } else if (score >= 70) { printf("良好,还不错\n"); } else if (score >= 60) { printf("及格,要再努力提高\n"); } else { printf("不及格,别灰心,加把劲\n"); }
return 0; }
|
控制语句
- 分支
- if
- switch
- 循环
- for
- while
- do…while
- 辅助控制
- continue
- break
- goto
- return
用{}
括起来的一组语句,(具有作用域功能)
1 2 3 4 5 6 7 8 9 10
| int a = 2, b = 3, c; c = a + b; { int c; c = a * b; printf("%d \n", c); }
printf("%d", c);
|
自增自减,记忆
1 2 3 4 5 6 7 8 9 10
| int sum = 0; for (int i = 0; i <= 100; i++) { sum += i; } printf("%d", sum);
int x = 2, y = 2; printf("%d \n", x++); printf("%d", ++y);
|
输出空间大小sizeof
输出short, int, long, float, double, char等类型变量所占的存储空间大小
1 2 3 4 5 6
| printf("%d \n", sizeof(short)); printf("%d \n", sizeof(int)); printf("%d \n", sizeof(long)); printf("%d \n", sizeof(float)); printf("%d \n", sizeof(double)); printf("%d \n", sizeof(char));
|
编程小工具
1 2
| system("chcp 65001"); fflush(stdin);
|
输出字符数组
1 2 3 4 5
| char st = 'A'; printf ("bar = %c ", st);
char str[10] = "abc_123"; printf ("bar = %s ", str);
|