大佬教程收集整理的这篇文章主要介绍了线程1:EXC_BAD_ACCESS(代码= 1,地址= 0x0)标准C内存问题,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
typedef struct { int start; int stop; char *strandID; } LOCATIOn; int main(int argc,const char * argv[]) { if (argc != 4) { fprintf(stderr,"Usage is ./a.out windowfile.txt genefile.txt outputFilename"); exit(-1); } //const vars const char *windowInput = argv[1]; const char *geneInput = argv[2]; const char *outputfile = argv[3]; const int windowHeader = 9; const int geneHeader = 3; //get size of structures -- I have debugged and these work correctly,returning the size of my structure const int posWsize = getSize(windowInput,"+",windowHeader); const int negWsize = getSize(windowInput,"-",windowHeader); const int posGsize = getSize(geneInput,geneHeader); const int negGsize = getSize(geneInput,geneHeader); //declare structs LOCATIOn posWindow[posWsize]; LOCATIOn negWindow[negWsize]; LOCATIOn posGene[posGsize]; LOCATIOn negGene[negGsize]; //extract data here getLOCATIOns(posWindow,negWindow,windowInput,windowHeader); return 0; } void getLOCATIOns(LOCATIOn *posL,LOCATIOn *negL,const char *input,const int header) { FILE *fileptr = NULL; fileptr = fopen(input,"r"); //open file if (fileptr == NULL) { //check for errors while opening fprintf(stderr,"Error reading %s\n",input); exit(-1); } char tmpLoc[20]; char tmpID[2]; int eofVar = 0; int lineCount = 0; while (lineCount < header) { //skip header and get to data eofVar = fgetc(fileptr); if (eofVar == '\n') lineCount++; } int pCount = 0; int nCount = 0; while (eofVar != EOF) { fscanf(fileptr,"%s %s",tmpLoc,tmpID); //scan in first two Strings if (!strcmp(tmpID,"+")) { //if + strand char *locTok = NULL; locTok = strtok(tmpLoc,".."); //tok and get values posL[pCount].start = atoi(locTok); locTok = strtok(NULL,".."); posL[pCount].stop = atoi(locTok); //ERROR IS SHOWN HERE posL[pCount].strandID = tmpID; printf("start=%d\tstop=%d\tID=%s\Tindex=%d\n",posL[pCount].start,posL[pCount].stop,posL[pCount].strandID,pCount); pCount++; } else if (!strcmp(tmpID,"-")) { //if - strand char *locTok = NULL; locTok = strtok(tmpLoc,".."); //tok and get values negL[nCount].start = atoi(locTok); locTok = strtok(NULL,".."); negL[nCount].stop = atoi(locTok); negL[nCount].strandID = tmpID; nCount++; } while ((eofVar = fgetc(fileptr)) != '\n') { if (eofVar == EOF) break; } } fclose(fileptr); } //dynamic way...same issue -- just replace this with the above if statement and use the create LOCATIOn function if (!strcmp(tmpID,"+")) { //if + strand int locStart; int locStop; locStart = atoi(strtok(tmpLoc,".."));//tok and get values locStop = atoi(strtok(NULL,"..")); posL[pCount] = *createLOCATIOn(locStart,locStop,tmpID); pCount++; } LOCATIOn *createLOCATIOn(int start,int stop,char *strandID) { LOCATIOn *tmp = NULL; tmp = (LOCATIOn *) malloc(sizeof(LOCATIOn) * 1); tmp->start = start; tmp->stop = stop; tmp->strandID = (char *) malloc(sizeof(char) * 2); strcpy(tmp->strandID,strandID); return tmp; }
以上是大佬教程为你收集整理的线程1:EXC_BAD_ACCESS(代码= 1,地址= 0x0)标准C内存问题全部内容,希望文章能够帮你解决线程1:EXC_BAD_ACCESS(代码= 1,地址= 0x0)标准C内存问题所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。