fwrite写入后fread读取不出来问题,求帮助
程序代码:
nzmc * tmpMusic = new nzmc[numRow]; for(int i = 0; i < numRow; i++) { row = mysql_fetch_row(res); /* 循环保存在结构体中 */ tmpMusic[i].mcName = row[1]; tmpMusic[i].mcJp = row[2]; tmpMusic[i].comm = atoi(row[3]); } if(access(FILEJ, 0) == -1) mkdir(FILEJ); FILE * fp; if((fp = fopen(FILEJ"\\data.dat", "w+b")) == NULL) return -7; fwrite(&tmpMusic[0], sizeof(nzmc), numRow, fp); if(ferror(fp)) return -8; delete [] tmpMusic; fclose(fp); fileRead(); } int fileRead(void) { nzmc * tmpnc = new nzmc[1000]; FILE * fp = NULL; if((fp = fopen(FILEJ"\\data.dat", "r+b")) == NULL) return -9; int tmp = 0; while (!feof(fp)) { fread(&tmpnc[tmp], sizeof(nzmc), 1, fp); tmp++; }其中 ,结构体数组中的一项数据为:
{"月亮代表我的心","g:150|q:150|e:150|t:150|q:150|j:150|e:150|t:500|t:150|y:150|u:150|p:150|y:150|t:500|e:150|w:150|q:150|q:150|q:500|e:150|w:150|q:150|q:150|q:500|w:150|e:150|w:150|q:150|h:150|w:150|e:150|w:500|g:150|q:150|e:150|t:150|q:150|j:150|e:150|t:500|t:150|y:150|u:150|p:150|y:150|t:500|e:150|w:150|q:150|q:150|q:500|e:150|w:150|q:150|q:150|q:500|w:150|e:150|w:150|h:150|j:150|q:150|w:150|q:500|e:150|t:150|e:150|w:150|q:150|t:150|j:500|h:150|j:150|h:150|j:150|h:150|g:150|e:500|t:150|e:150|w:150|q:150|t:150|j:500|h:150|j:150|q:150|q:150|q:150|w:150|e:150|w:500|g:150|q:150|e:150|t:150|q:150|j:150|e:150|t:500|t:150|y:150|u:150|p:150|y:150|t:500|e:150|w:150|q:150|q:150|q:500|e:150|w:150|q:150|q:150|q:500|w:150|e:150|w:150|h:150|j:150|q:150|w:150|q:500|",0},
结构体数组有很多由上面数据组成,但是写入文件,使用fread批量读取出来以后,只能读取“月亮代表我的心”和“0”,中间的一大串曲谱读取不出来,显示为空,且请高手查看代码给予帮助。谢谢了
[ 本帖最后由 cnnidajie 于 2013-2-11 09:43 编辑 ]