2015-04-06 62 views
0

我试图在C中读取.au文件的头文件,并且我将所有值存储在struct中,但无法将它们转换为Little Endian格式。AU文件的读取头 - C

我偶然发现了一个方法,ntohl应该把字节和转换为主机格式,但编译我的程序时不断收到错误。

undefined reference to 'ntohl'

#include <stdio.h> 

struct header 
{ 
    char magic[5]; 
    int offset; 
    int size; 
    int encoding; 
    int rate; 
    int channels; 
}; 

int main() 
{ 
    FILE *fin, *fout; 
    struct header au; 
    char path[10]; 

    printf("Enter name of file to be processed: "); 
    scanf("%s", path); 

    fin = fopen(path, "r"); 
    fout = fopen("out.au","w"); 

    fscanf(fin, "%s %d %d %d %d %d", &au.magic, &au.offset, &au.size, &au.encoding, &au.rate, &au.channels); 
    printf("%s\n%d\n%d\n%d\n%d\n%d\n", au.magic, ntohl(au.offset), ntohl(au.size), ntohl(au.encoding), ntohl(au.rate), ntohl(au.channels)); 
} 

我在报头值读数是否正确?

回答

1

Linux OS ntohlarpa/inet.h(或netinet/in.h)头文件中声明。在Windows这是Winsock2.h

至于读取头的正确性,这是不正确的。您正在做fscanf(fin, "%s %d %d %d %d %d...这是试图读取其文本表示中的数字,用空格分隔,这完全不是AU file表示的方式。该文件类型是一个二进制文件,应该使用fread作为二进制文件读取。