Read and write to binary files in C?

后端 未结 6 1371
梦如初夏
梦如初夏 2020-11-27 13:02

Does anyone have an example of code that can write to a binary file. And also code that can read a binary file and output to screen. Looking at examples I can write to a fi

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-27 13:45

    This is an example to read and write binary jjpg or wmv video file. FILE *fout; FILE *fin;

    Int ch;
    char *s;
    fin=fopen("D:\\pic.jpg","rb");
    if(fin==NULL)
         {  printf("\n Unable to open the file ");
             exit(1);
          }
    
     fout=fopen("D:\\ newpic.jpg","wb");
     ch=fgetc(fin);
           while (ch!=EOF)
                 { 
                      s=(char *)ch;
                      printf("%c",s);
                     ch=fgetc (fin):
                     fputc(s,fout);
                     s++;
                  }
    
            printf("data read and copied");
            fclose(fin);
            fclose(fout);
    

提交回复
热议问题