接分
报告老师,我低头不是因为我在装低调,是你问的问题,我真的不会答,,,
bool Load_Header(FILE* file, Header* header) { char buffer[1024]; bool success = true; bool inHeader = false; while (success && !ferror(file) && !feof(file) && fgets(buffer, _countof(buffer), file)) { if (*Str_Trim(buffer) == '\n') { continue; } if (!inHeader) { _strupr_s(buffer, _countof(buffer)); if (strcmp(buffer, "[HEADER]\n") == 0) { inHeader = true; continue; } } if (inHeader) { sscanf_s(buffer, "Fields Number: %u", &header->Field_Number); header->Fields = (Field*)calloc(header->Field_Number, sizeof(Field)); if (header->Fields) { size_t index = 0; while ((index < header->Field_Number) && fgets(buffer, _countof(buffer), file)) { if (*Str_Trim(buffer) != '\n') { Get_String(buffer, header->Fields[index].Name, sizeof(header->Fields[index].Name), '\"'); const char* p = strchr(buffer, '='); if (p) { sscanf_s(p + 1, " %1c", &header->Fields[index].Type, 1); } else { header->Fields[index].Type = 'U'; } p = strchr(buffer, '['); if (!p || (sscanf_s(p, "[%d,%d]", &header->Fields[index].Length, &header->Fields[index].Decimal) != 2)) { success = false; break; } ++index; } } } break; } } return success; }
[此贴子已经被作者于2015-12-25 09:27编辑过]