TableOfContents

实验基本要求

实验运行环境简介

1. DEV-C++集成开发环境

安装运行

  1. 下载安装程序: http://www.bloodshed.net/dev/devcpp.html

  2. 运行安装程序进行安装
  3. 运行集成开发环境:开始菜单=〉Bloodshed Dev-C++ =〉Dev-C++

工程创建

  1. 在Dev-C++菜单中选择File=>New=>Project

  2. 在弹出对话框中选择Console Application,选中C Project,Name框输入一个工程名字,最后按OK按钮
  3. 选择硬盘上某个路径保存你所建立的工程

程序运行

  1. 选择菜单Execute=>Compile编译程序

  2. 如果编译没有错误,选择Execute=>Run运行程序,得到运行结果

如果程序结果一闪而过,怎么办?

调试程序

2. Visual Studio.Net 2003集成开发环境

创建工程

  1. 打开Visual Studio.net 2003集成开发环境
  2. 菜单File=>New=>Project

  3. 在弹出的对话框中:Project Types选择Visual C++ Projects,Templates选择Win32 Console Application,Name中输入工程名称,Location选择保存的路径。最后点OK
  4. 在接下来的工程向导中,选择Application Settings,选择Empty Project,最后按Finish
  5. 菜单View=>Solution Explorer

  6. 在Solution Explorer中选中刚才建立的工程
  7. 菜单File=>Add New Item

  8. 在弹出的对话框中:Categories选择Visual C++,Templates选择C++ File,Name中输入文件名,文件要以.c结尾,最后按Open。

编译运行

  1. 菜单Build=>Build Solution

  2. 如果编译通过,选择菜单Debug=>Start Without Debugging

调试

实验1-1

1. 实验目的

熟悉C语言开发环境,学会

2. 实验内容

编译运行以下程序,观察程序运行的结果 完成课后作业1-1

   1 #include <stdio.h>
   2 main() 
   3 {
   4         printf("hello, world\n");
   5 }

   1 #include <stdio.h>
   2 /* print Fahrenheit-Celsius table for fahr = 0, 20, ..., 300 */
   3 main ()
   4 {
   5     int fahr,  celsius;
   6     int lower, upper, step;
   7     lower = 0;
   8     upper = 300;
   9     step = 20;
  10     fahr = lower;
  11     while ( fahr <= upper) {
  12         celsius = 5 * (fahr - 32) / 9;
  13         printf( "%d\t%d\n", fahr, celsius);
  14         fahr = fahr + step;
  15     } 
  16 }

   1 #include <stdio.h>
   2 /* print Fahrenheit-Celsius table*/
   3 main()
   4 {
   5     int fahr;
   6 
   7     for (fahr = 0; fahr <= 300; fahr = fahr + 20)
   8         printf("%3d %6.1f\n", fahr, (5.0/9.0)*(fahr-32));
   9 }

{{{1-1 Run the "hello, world" program on your system. Experiment with leaving out parts of the program, to see what error messages you get. }}}

实验2-1

1. 实验目的

2. 实验内容

写一个函数strinsert(s, n, t)在字符串s的第n个字符后面插入字符串t。比如:

   1 char s[100] = "write everywhere";
   2 char t[] = "once, run ";
   3 strinsert(s, 6, t);
   4 printf("%s", s); 

输出: {{{write once, run everywhere }}}

实验2-2

1. 实验目的

2. 实验内容

写两个函数

for example:

   1 char s[20]="hello world";
   2 char t[20]="hello world";
   3 strcrop(s, 1, 8);
   4 strdel(t, 1, 8);
   5 printf("%s\n%s\n", s, t); 

output:

ello wor
hld 

实验2-3

1. 实验目的

熟悉指针数组的使用

2. 实验内容

写一个函数weekday(y,m,d),求取y年m月d日是星期几,返回星期几的名字。例如:

   1 printf("%s", weekday(2006,3,6));

输出

ch3n2k.com | Copyright (c) 2004-2020 czk.