-1

I'm trying to write an array of 18000 items (that array is from the transformation wav>array), and when I write the items in a file appears a \n when I don't want to write that, here is the code:

f = info.frames;
sr = info.samplerate;
c = info.channels;
num_items = f*c;
int arrayPrueba [num_items];

/* Allocate space for the data to be read, then read it. */
buf = (int *) malloc(num_items*sizeof(int));
num = sf_read_int(sf,buf,num_items);
sf_close(sf);
printf("Read %d items\n",num);

/* Write the data to filedata.out. */
out = fopen("filedata.data","a+");
fprintf(out,"13 18000 1\n");
int cont =0;

for (i = 0; i < num; i += c)
{
   for (j = 0; j < c; ++j)
        fprintf(out,"%d ",buf[i+j]);}
}
fprintf(out,"\n%d\n",pasos);
fclose(out);

Here is a part of filedata.data where appears that jump of line

    104333312 103415808 104202240 105250816 104595456 104202240 103022592 103415808 102367232 102236160 104202240 104071168 104464384 103677952 103284736 103809024 102760448 103415808 105644032 102629376 102629376 103940096 103022592 103284736 102891520 104726528 103677952 103284736 102891520 104071168 104202240 102498304 102760448 102367232 100007936 102498304 104071168 104202240 103153664 103940096 103153664 103022592 103284736 103940096 103677952 103546880 102629376 103546880 101974016 102498304 104071168 103546880 103677952 103940096 103284736 102105088 105119744 104071168 103677952 103415808 104071168 104726528 103546880
 103415808 103677952 103940096 105512960 104857600 103940096 103809024 102760448 103022592 103284736 103022592 103153664 104333312 102891520 103940096 104464384 103677952 103940096 102105088 103022592 102629376 104595456 103940096 102236160 102760448 102629376 103940096 102236160 104726528 102760448 102629376 102760448

It jumps between 103546880 and 103415808.

I need it without \n breakup's because the file.data for FANN training and it can't have jumps.

4

3 回答 3

2

我无法想象 C 库添加不需要的换行符。普通操作系统和文件系统(Windows 和其他类 Unix)也不应该。除非您使用的是非常不常见的操作系统或文件系统——如果是,你真的应该在你的问题中添加它——我认为当你打开文件以供编辑器阅读时,编辑器添加了不需要的换行符。

要确认,请使用适用于许多平台的优秀vim。它几乎可以读取所有内容,甚至包含空字符的文件,并且可以转换为十六进制以确保文件中的内容。

我刚刚创建了一个包含 32000 个元素的文件,每个元素包含 10 个字符('104333312'),vim 说该行有 320000 个字符而没有尝试拆分它(当然该行是折叠的,但正确地算作一行)。

于 2014-08-11T11:36:36.720 回答
0

问题一定来自:

info.samplerate;

无论从哪里收集数据,都可能导致嵌入换行符。可能是采样中的一些怪癖,或者它超出了缓冲区,提示要写入新的缓冲区/数据行。您在换行符之前获得了多少数据条目?

于 2014-08-11T10:14:28.127 回答
-2

替换行out = fopen("filedata.data","a+"); 用下面的线。例如 out = fopen("filedata.data","a+b");

所以文件不会有换行符(\n)。

于 2014-08-11T10:32:47.833 回答