| 
 | 
 
代码如下: 
#include <stdio.h> 
#define max 60 
#define min 3 
main() 
{ 
        int count; 
        int i; 
        char name[max]; 
        char extname[]="jpg"; 
        FILE *fp; 
        FILE*fp2; 
        int c; 
        int zero='0'; 
 
        printf("Please input the name of the file"); 
        scanf("%s",name); 
        printf("\n"); 
        printf("Please input file count"); 
        scanf("%d",&count); 
        printf("\n"); 
 
        fp=fopen("dmtmp","wr"); 
        for( i = 0; i < count ; i++){ 
                fprintf(fp,"%s",name); 
                fprintf(fp,"%3d",i); 
                fprintf(fp,"%3d",i+1); 
                fprintf(fp,".%s",extname); 
                fprintf(fp,"\n"); 
        } 
         
        rewind(fp); 
        fp2=fopen("dmlist","w"); 
         
        while((c = getc(fp)) != EOF){ 
                if ( c == ' ') 
                        putc('0',fp2); 
                else 
                        putc(c,fp2); 
        } 
 
        fclose(fp); 
        fclose(fp2); 
} 
         
编译的时候用的gcc,编译没有任何问题。但是结果出来后,dmlist文件却总是空的,而tmp文件则按我预想的写满了内容。我参考了下面这段程序: 
#include <stdio.h> 
 
main(int argc, char *argv[]) 
{ 
        FILE *fp; 
        void filecopy(FILE * , FILE * ); 
 
        if ( argc == 1 ) 
                filecopy(stdin,stdout); 
        else 
                while ( --argc > 0) 
                         if((fp=fopen(*++argv,"r")) == NULL ){ 
                                printf("cat:can'topen %s\n",*argv); 
                                return 1; 
                        }else{ 
                                filecopy(fp,stdout); 
                                fclose(fp); 
                        } 
                        return 0; 
} 
 
void filecopy(FILE *ifp, FILE *ofp) 
{ 
        int c; 
 
        while ((c = getc(ifp)) != EOF) 
                if(c == ' ') 
                        putc('0',ofp); 
                else 
                        putc(c,ofp); 
                 
} 
 
这段程序可以正常工作~~ 
 
[ 本帖最后由 tandkzy 于 2007-7-19 11:55 编辑 ] |   
 
 
 
 |