【发布时间】:2016-04-05 08:23:26
【问题描述】:
我是 C 编程新手,在播放音符的 MIDI 录音程序上做一些工作,但似乎无法让程序从文件中读取到我的结构数组中。
结构如下:
typedef struct
{
int noteNumber;
int vel;
int oscillatorNumber;
float freq;
} oneNote;
这里是阅读注释的代码:
oneNote notes[2000];
for (count = 0; count < fileSize; count++)
{
fscanf(filePointer, "%d %d %d\n", ¬es[count].noteNumber,
¬es[count].vel,
¬es[count].oscillatorNumber);
notes[count].freq = ntof(notes[count].noteNumber);
}
文件打开的代码:
filePointer = fopen("noteRecordFile.txt", "r");
if (filePointer == NULL)
{
printf("Error opening file\n");
}
else
{
printf("File opened\n");
fseek(filePointer, 0L, SEEK_END);
fileSize = ftell(filePointer);
}
只是不存储结构中的数据和,如下所示:
noteRecordFile.txt 的前几行:
48 108 0
50 108 0
52 100 0
【问题讨论】:
-
请提供您打开文件的代码部分
-
我现在已经完成了,当我运行程序时它说文件已打开
-
请提供
noteRecordFile.txt文件的前几行。 -
我已将其编辑到帖子中
-
在确定文件长度的过程中,您已经到达文件末尾。您是否忘记使用
fseek(filePointer, 0L, SEEK_SET)回到文件开头?
标签: c midi audio-player