請考慮以下內容。爲什麼sizeof返回「23」?我怎樣才能得到真正的大小? (不計嘿嘿)字符數組的大小給出了大量的標記值
char defaultsettings[] = "<?xml version=\"1.0\"?>\n";
strcat(defaultsettings, "<CsSettings>\n<options>\n");
strcat(defaultsettings, "<spin name=\"maxTries\" value=\"1000\" />\n");
strcat(defaultsettings, "<spin name=\"rollCount\" value=\"1\" />\n");
strcat(defaultsettings, "<check name=\"matchItems\" value=\"1\" />\n");
strcat(defaultsettings, "<check name=\"highlightItems\" value=\"1\" />\n");
strcat(defaultsettings, "<check name=\"buyListMode\" value=\"0\" />\n");
strcat(defaultsettings, "<radio name=\"matchItemType\" value=\"0\" />\n");
strcat(defaultsettings, "<check name=\"matchLocations\" value=\"0\" />\n");
strcat(defaultsettings, "<check name=\"highlightLocations\" value=\"1\" />\n");
strcat(defaultsettings, "<check name=\"allMissionsSameLocation\" value=\"0\" />\n");
strcat(defaultsettings, "<check name=\"highlightFind\" value=\"0\" />\n");
strcat(defaultsettings, "<check name=\"highlightReturn\" value=\"0\" />\n");
strcat(defaultsettings, "<check name=\"highlightRepair\" value=\"0\" />\n");
strcat(defaultsettings, "<check name=\"highlightPerson\" value=\"0\" />\n");
strcat(defaultsettings, "<check name=\"highlightKill\" value=\"0\" />\n");
strcat(defaultsettings, "<check name=\"ignoreFind\" value=\"0\" />\n");
strcat(defaultsettings, "<check name=\"ignoreReturn\" value=\"0\" />\n");
strcat(defaultsettings, "<check name=\"ignoreRepair\" value=\"0\" />\n");
strcat(defaultsettings, "<check name=\"ignorePerson\" value=\"0\" />\n");
strcat(defaultsettings, "<check name=\"ignoreKill\" value=\"1\" />\n");
strcat(defaultsettings, "<combo name=\"itemValueBase\" value=\"1\" />\n");
strcat(defaultsettings, "<check name=\"matchMissionValue\" value=\"0\" />\n");
strcat(defaultsettings, "<spin name=\"matchMissionMinValue\" value=\"10000\" />\n");
strcat(defaultsettings, "<check name=\"levelCalcFixerMode\" value=\"0\" />\n");
strcat(defaultsettings, "<spin name=\"bneBonus\" value=\"1\" />\n");
strcat(defaultsettings, "<spin name=\"levelCalc\" value=\"1\" />\n");
strcat(defaultsettings, "<spin name=\"missionCalc\" value=\"1\" />\n");
strcat(defaultsettings, "<check name=\"log\" value=\"0\" />\n");
strcat(defaultsettings, "<entry name=\"useKey\" value=\"e\" />\n");
strcat(defaultsettings, "</options>\n<items>\n</items>\n");
strcat(defaultsettings, "<locations>\n<location>\n<string>Milky way</string>\n");
strcat(defaultsettings, "<x>\n<var>3050</var>\n<var>3400</var>\n</x>\n");
strcat(defaultsettings, "<y>\n<var>1000</var>\n<var>1200</var>\n</y>\n");
strcat(defaultsettings, "<ignore>1</ignore>\n<enabled>1</enabled>\n");
strcat(defaultsettings, "<coordsEnabled>1</coordsEnabled>\n");
strcat(defaultsettings, "</location>\n<location>\n<string>Milky way</string>\n");
strcat(defaultsettings, "<x>\n<var>3500</var>\n<var>3850</var>\n</x>\n");
strcat(defaultsettings, "<y>\n<var>700</var>\n<var>950</var>\n</y>\n");
strcat(defaultsettings, "<ignore>1</ignore>\n<enabled>1</enabled>\n");
strcat(defaultsettings, "<coordsEnabled>1</coordsEnabled>\n");
strcat(defaultsettings, "</location>\n</locations>\n</CsSettings>");
printf("%s\nSize: %d\n\n",defaultsettings,sizeof(defaultsettings));
輸出:
[...]
</location>
</locations>
</CsSettings>
Size: 23
感謝C語言,看起來不好的代碼通常是不好的。使用文件。 – 2011-05-01 17:53:10