// ini file read and write sample // // Windows10 x64 22H2 + MinGW (gcc 6.3.0) // Last updated: <2024/01/14 04:00:18 +0900> #include #include #include #include #define INIFILENAME "test.ini" #define SECNAME "ssstarsgl_config" // global work int wait = 15; int speed = 1000; int number = 500; int fps_disp_enable = 0; int main(void) { char cdir[MAX_PATH]; char filepath[MAX_PATH]; // get current directory GetCurrentDirectory(MAX_PATH, cdir); // create save file path PathCombine(filepath, cdir, INIFILENAME); printf("Current Directory : %s\n", cdir); printf("ini file path : %s\n\n", filepath); if (!PathFileExists(filepath)) { // Not found ini file printf("Not found %s\n", filepath); printf("Create %s\n\n", filepath); char buf[256]; // create/write ini file sprintf(buf, "%d", wait); WritePrivateProfileString(SECNAME, "wait", buf, filepath); sprintf(buf, "%d", speed); WritePrivateProfileString(SECNAME, "speed", buf, filepath); sprintf(buf, "%d", number); WritePrivateProfileString(SECNAME, "number", buf, filepath); sprintf(buf, "%d", fps_disp_enable); WritePrivateProfileString(SECNAME, "fps_disp_enable", buf, filepath); } if (!PathFileExists(filepath)) { printf("Not found %s\n\n", filepath); return -1; } else { printf("Found %s\n", filepath); // read ini file printf("Read ini file\n"); wait = GetPrivateProfileInt(SECNAME, "wait", -1, filepath); speed = GetPrivateProfileInt(SECNAME, "speed", -1, filepath); number = GetPrivateProfileInt(SECNAME, "number", -1, filepath); fps_disp_enable = GetPrivateProfileInt(SECNAME, "fps_disp_enable", -1, filepath); // dump results printf("wait = %d\n", wait); printf("speed = %d\n", speed); printf("number = %d\n", number); printf("fps_disp_enable = %d\n", fps_disp_enable); } return 0; }