摘选的一些问题:
1、把大型的程序放入一个单一的源文件中有什么优缺点?
优点:避免了重复定义的错误。避免了声明。
确定:显而易见,一个4万行程序的c文件是令人发指的。
2、编写一个程序,它从标准输入读取C源代码,并验证所有的花括号都成对地出现。- // 成对输入花括号.cpp : 定义控制台应用程序的入口点。
- //
- #include "stdafx.h"
- #include "stdio.h"
- #include "stdlib.h"
- int _tmain(int argc, _TCHAR* argv[])
- {
- int Add = 0;
- char temp;
- while ((temp = getchar()) != EOF )
- {
- if (temp == '}')
- {
- if (Add == 0)
- {
- printf("wrong!");
- }
- else
- Add -= 1;
- }
- if (temp == '{')
- {
- Add += 1;
- }
- }
- return EXIT_SUCCESS;
- }
|