c程式語言設計 1-23
阿新 • • 發佈:2018-12-23
c複習第三彈
做了1-23,挺難的,也沒有做的很完善
#include <stdio.h>
/************
*測試1
*
*
* ***********/
void main(int argc,char *argv[])
{
int c;
int flag = 0;
int number = 0;
FILE *fp;
if(argc != 2)
{
printf("格式錯了,");
return ;
}
if((fp = fopen(argv[1],"r" ))==NULL)
{
printf("沒這檔案");
return ;
}
// 測試2
while((c = fgetc(fp)) != EOF)
{
if(c == '/' && flag == 0){
flag = 1;
number = 0;
}
if(c == '/' && flag == 1 && number == 1)flag = 2;
if(c == '\n' && flag == 2 )flag = 0;
if(c == '*' && flag == 1 && number == 1)flag = 3;
if(c == '/' && flag == 3)flag = 0;
if(flag > 1 ){
;
}else{
putchar(c);
number++;
}
}
fclose(fp);
}