|
发表于 2004-3-31 20:31:16
|
显示全部楼层
请看看错在那里,请指正!!
# cat tmp.filea
//abcd
//while
hello ,the world
// test program
/* comment*/
end
- # cat change_comment.c
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- int main( void )
- {
- FILE *fp,*fd;
- char buffer[8139];
- int count;
- if((fd=fopen("tmp.fileb","w+"))<0) {
- printf("open tmp.fila error\n");
- return(1);
- }
- if((fp = fopen( "tmp.filea", "r" )) != NULL ) {
- while( fgets( buffer, 80, fp ) != NULL ) {
- if(buffer[0] == '/' && buffer[1] == '/' ) {
- count=sizeof(buffer);
- buffer[count-1]='*' ;
- buffer[count]='/';
- buffer[count+1]='\n';
- buffer[1]='*' ;
- }
- fputs( buffer,fd );
- fputs( buffer,stdout);
- }
- fclose( fp );
- fclose( fd );
- }else {
- printf("open tmp.filea error\n");
- return(1);
- }
- printf("\n");
- return(0);
- }
- # ./a.out
- /*abcd
- /*while
- hello ,the world
- /* test program
- /* comment*/
- end
复制代码 |
|