小编Sea*_*ean的帖子

用标准库写入文件

我从未在将数据写入文件方面遇到太多麻烦!我正在从MinGW运行GCC,因为我习惯在Linux中使用GCC.我通常使用Linux系统调用open(),write()和read(),但我现在正在编写一个Windows程序,而我在Windows中使用read()/ write()时遇到了麻烦,所以我只是在使用标准库.无论如何,我遇到的问题是我不知道如何写入文件!我已经定义了"FILE*"变量,使用fopen(),"r + b","wb"和"w + b",但我仍然无法用fwrite()或fprintf()写入输出文件.我不知道我甚至做错了什么!这是我的来源:

#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>

#define DEBUG   1

/*** Global functions ***/
double  highfreq(double deg);

/*** Global variables ***/
double  sin_now;

unsigned int    *ptr;
unsigned char   *key,   *infilename,    *outfilename;
FILE    *infile,    *outfile,   *keyfile;

const char  *pipe_name="[pipe]";

int main(int argc, char *argv[]) {
    unsigned int    x,  y,  z;

    if(argc!=3) {
        fprintf(stderr, "Syntax error: %s <infile.txt> <outfile.wav>", argv[0]);
        return 1;
    }
    if(argv[1][0]=='-') {
        infile=stdin;
        infilename=(unsigned char *)pipe_name;
    }
    else {
        infilename=argv[1]; …
Run Code Online (Sandbox Code Playgroud)

c printf fopen fwrite fread

1
推荐指数
1
解决办法
206
查看次数

标签 统计

c ×1

fopen ×1

fread ×1

fwrite ×1

printf ×1