编译器练习:将C程序中的注释中的小写字母转换为大写字母
来源:互联网 发布:linux下的git管理工具 编辑:程序博客网 时间:2024/04/30 00:31
/*filename:notes.c
programed by:alex shoal
edit date:2009-2-9
revision:1
****************
reference:
"compiler construction principles and practice"
page 42~43 DFA design
****************
*/
#include <stdio.h>
#include <stdlib.h> // ANSI C exit() prototype
int is_lowercase(int);
int is_uppercase(int);
int main(int argc, char *argv[])
{
int ch; // place to store each character as read
int state=0;
FILE *fp; // "file pointer"
if (argc != 2){
printf("Usage: %s filename/n", argv[0]);
exit(1);
}
if ((fp = fopen(argv[1], "r")) == NULL){
printf("Can't open %s/n", argv[1]);
exit(1);
}
while (((ch = getc(fp)) != EOF)){
switch(state){
case 0:{ if(ch=='/') state=1; break; }
case 1:{ switch(ch){
case '*': state=2;break;
case '/': state=4;break;
default : state=0;break;
}
break;
}
case 2:{ if(ch=='*') state=3;break; }
case 3:{ if(ch=='/') state=0;else state=2;}
case 4:{ if(ch==10 ) state=0;} //if ch == '/n', exit
}
if(is_lowercase(ch)==1&&(state==2||state==4))
putc(ch-32,stdout);
else putc(ch,stdout);
}
fclose(fp);
return 0;
}
int is_lowercase(int ch){
if (ch>=97&&ch<=122)
return 1;
else return 0;
}
int is_uppercase(int ch){
if (ch>=65&&ch<=90)
return 1;
else return 0;
}
- 编译器练习:将C程序中的注释中的小写字母转换为大写字母
- C/C++之将串中的小写字母转换为大写字母
- C语言toupper()函数:将小写字母转换为大写字母
- c语言将小写字母转换为大写字母
- noi-8175-将字符串中的小写字母转换成大写字母
- 13:将字符串中的小写字母转换成大写字母
- 将字符串中的小写字母转换成大写字母
- 13.将字符串中的小写字母转换成大写字母
- 将大写字母转换为小写字母
- 将小写字母转换为大写字母
- 将小写字母转换为大写字母
- 将大写字母转换为小写字母
- 将小写字母转换为大写字母
- 在Linux下如何将文本文件中的大写字母全部转换为小写字母
- c将大写字母转换成小写字母
- C语言小写字母转换为大写字母
- 转换小写字母为大写字母
- 小写字母转换为大写字母
- 学8大必瘦秘诀 2009减肥绝对成功
- ORACLE联机日志文件丢失或损坏的处理方法
- MyEclipse的Tcp/Ip monitor
- 第一次滇缅作战总结:史迪威无能 英国佬无耻
- 电子海图 ecdis ens vts
- 编译器练习:将C程序中的注释中的小写字母转换为大写字母
- POSTGRESQL的JDBC中的存储过程
- 找到我需的资料
- ????
- 酒桌上的潜规则,男人必学,女人必知!
- 一个简单的C#多线程间同步的例子
- Asp.net 网络打印
- Hibernate注释大全(转)
- 1979年前后的中美关系