This is from my .ini parser:
PHP Code:
// check if this is a session line (e.g., [SECTION])
if (str[0] == '[' && str[length - 1] == ']') {
strcpy(section, &str[1]);
section[length - 2] = 0; // remove the ]
This works in Windows, but in GNU/Linux I have to use:
PHP Code:
// check if this is a session line (e.g., [SECTION])
if (str[0] == '[' && str[length - 2] == ']') {
strcpy(section, &str[1]);
section[length - 3] = 0; // remove the ]
The problem is, why does the GNU/Linux has to use a different way ? Also I'm using gcc 3.4.2 for both of the OS's
I have also pre-processed the string read from the .ini file with this function:
PHP Code:
void trim(char *str)
{
int pos = 0;
char *dest = str;
// skip leading blanks
while (str[pos] == ' ' || str[pos] == '\t' || str[pos] == '\n')
pos++;
while (str[pos]) {
*dest++ = str[pos];
pos++;
}
*dest = '\0'; // store the null
int i = strlen(str) - 1;
while (i > 0 && (str[i] == ' ' || str[i] == '\t' || str[i] == '\n')) { // remove trailing blanks
str[i--] = '\0';
}
}