ThreadBoard ArchivesSite FeaturesActiveworlds SupportHistoric Archives |
A bit of help :) (Sdk)
A bit of help :) // Sdkbyte meOct 16, 1998, 4:02pm
Heres an idea :)
can someone tell me how to make my bot read an ini? :) jwOct 16, 1998, 7:24pm
i worked on that a while ago. i created a simple ini file reader which
may be useful: source: #include <time.h> #include <math.h> #include <errno.h> #include <ctype.h> #include <conio.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <assert.h> #include <stdargs.h> main() { char *file_loc = "E:\\BORLANDC\\OUTPUT\\test.ini"; char line1[81], line1_default[] = "user="; char line2[81], line2_default[] = "install dir="; FILE *fp; size_t change_loc; int count = 0, count_to = 0; fp = fopen(file_loc, "r"); /* this */ fgets(line1, 80, fp); /* code */ fgets(line2, 80, fp); /* area */ /* checks */ change_loc = strspn(line1, line1_default); /* the */ if(change_loc < 5) /* ini */ { /* file */ printf("Corrupt ini file. Please reinstall."); /* for */ exit(1); /* changes */ } /* to */ /* the */ change_loc = strspn(line2, line2_default);/* setup */ if(change_loc < 12) /* of */ { /* the */ printf("Corrupt ini file. Please reinstall."); /* ini */ exit(1); /* prog */ } /* file */ //start ini file line 1 fseek(fp, 5, 0); count_to = (strlen(line1) - 5); line1_count_start:; if(line1[count] != '\n' && line1[count] != '\0' && line1[count] != '\r') line1[count++] = fgetc(fp); if(count < count_to) goto line1_count_start; line1[--count] = '\0'; //end ini file line 1 //start ini file line 2 fseek(fp, (strlen(line1) + 19), 0); count_to = (strlen(line2) - 12); count = 0; line2_count_start:; if(line2[count] != '\n' && line2[count] != '\0' && line2[count] != '\r') line2[count++] = fgetc(fp); if(count < count_to) goto line2_count_start; line2[count] = '\0'; //end ini file line 2 printf("Hello %s. This program is installed to %s", line1, line2); } walter knupeOct 16, 1998, 9:04pm
Keep an eye on the windows api functions
GetPrivateProfileString GetPrivateProfileInt WritePrivateProfileString for own .ini files the best you can get :) e.g. WritePrivateProfileString("section","tag","value","myfile.ini"); creates or changes an "myfile.ini" that reads [section] tag=value and GetPrivateProfileString would be able to read that into a buffer or CString Walter |