thanks for your reply. "it fails" means the file was created but was empty.I realized that the file d:\\a.jpg doesn't exist there before the program runs,now i created it then execute the program,it successed. however,i can't understand my book says "a" will create a file when the file doesn't exist,campare with "w",:confused:why it produces different result?
D
Dengjin_CN
@Dengjin_CN
Posts
-
question about copy a picture with c [modified] -
question about copy a picture with c [modified]I wrote the code below to copy a picture,and why it will fail if i change the mode of fdest to "ab"? "ab" means write and add to file,isn't it?what's the difference?
#include<stdlib.h>
#include<stdio.h>#define MAX 1024
int
main(int argc,int **argv){FILE \*fsource,\*fdest; size\_t in; int buf\[MAX\]; fsource = fopen("F:\\\\a.jpg.rar","rb"); fdest = fopen("D:\\\\a.jpg","wb"); if(fsource == NULL || fdest == NULL) perror("open error"); while((in = fread(buf,sizeof(int),MAX,fsource)) != 0){ fwrite(buf,sizeof(int),in,fdest); fflush(fdest); } fclose(fsource); fclose(fdest); return EXIT\_SUCCESS;
}
modified on Saturday, October 17, 2009 5:49 AM
-
How write in perl ?It can't be discribed in a word,maybe the book named Learning Perl will help you ;)
-
I want to know some c librarieswell,everybody,I said C~~maybe you should tell me something likes GTK library,any others?I know GTK only... ;P ;P
-
I want to know some c librariesI'm a rookie to C and i'm looking for some libraries to learn,something likes the C++ STL or Boost ,does any1 can tell me some of them?Thanks a lot Eric