INI und Schleife
-
Hi,
ich habe diesen Code.
for(int a;a<100;++) { char temp[99]; GetPrivateProfileString("TEST", (char*)&a, "Default", temp, sizeof(temp), "test.ini"); }
In der INI-Datei steht:
[TEST] 0 = Irgendwas 1 = ... ... 100 = Irgentwasanderes
Nur leider findet das Pogramm diese Einträge nicht...
Was ist falsch?
-
Hi,
auf jeden Fall ist deine for Schleife murks ...
for(int a=0; a<100, a++){}
Legolas
-
(char*)&a
Das hier ist das Problem, versuch es mal wie folgt (ungetestet):
char Zahl[5]; sprintf(Zahl, "%i", a); GetPrivateProfileString("TEST", Zahl, "Default", temp, sizeof(temp), "test.ini");
-
So gehts ...
#include "Windows.h" int main(int argc, char* argv[]) { for(int a=0;a<100;a++) { char Zahl[5]; sprintf(Zahl, "%i", a); char temp[99]; GetPrivateProfileString("TEST", Zahl, "Default", temp, sizeof(temp), "e:\\Temp\\test.ini"); } return 0; }
Legoals
-
5. Parameter von GetPrivateProfileString():
nSize [in]: Size of the buffer pointed to by the lpReturnedString parameter, in TCHARs.
Das ist bestimmt nicht sizeof(temp), temp ist nämlich vom Typ char*, und sizeof(char*) == sizeof(int) und das ist nicht 99...
-
UncleSniper schrieb:
5. Parameter von GetPrivateProfileString():
nSize [in]: Size of the buffer pointed to by the lpReturnedString parameter, in TCHARs.
Das ist bestimmt nicht sizeof(temp), temp ist nämlich vom Typ char*, und sizeof(char*) == sizeof(int) und das ist nicht 99...
sizeof(temp) liefert hier 99 und _nicht_ sizeof(int). Dann waere temp naemlich vom Typ char *
mfg
v R