我正面临着下面这个function的问题。 我试图从一个位置获取数据,然后搜索指定的字符串。 之后我打印结果值。 这是第一次工作正常。 如果我使用for循环调用该函数但是我无法打印缓冲区值。
void parse_data(char *fname,int flag) { char str[30]="<Response>"; char buffer[1024],temp[1024],temp1[1024]; int nVal=0; FILE *fp; int s_pos; //string position in the text int c_pos; //char position in the text char *string; char ccnt; //char count long lSize; long pos=0; int c; s_pos = -1; c_pos = 0; fp=fopen(fname,"r"); //fseek(fp, 1, SEEK_SET); string = malloc(strlen(str)+1); if(fp==NULL) { printf("Unable to open the file n"); exit(0); } while (!feof(fp)) { if (c_pos == 0) { for (ccnt = 1; ccnt <= strlen(str); ccnt++) { if (!feof(fp)) { string[ccnt - 1] = getc(fp); if(nVal==1) { buffer[pos++] = string[ccnt -1]; } } //if }//for }//if if (c_pos != 0) if (!feof(fp)) { for (ccnt = 0; ccnt <= strlen(str) - 2; ccnt++) string[ccnt] = string[ccnt + 1]; string[strlen(str) - 1] = getc(fp); if(nVal==1){ buffer[pos++] = string[strlen(str) - 1]; } } if (strcmp(string, str) == 0) { strcpy(str,"</Response>"); s_pos = c_pos; if(nVal==1){ buffer[pos-strlen(str)]='