سؤال

Quick question: I am using data from a .conf file to connect to a Gameserver; I'm using sscanf to parse through the file, whitespaces being ignored as they should, however to test my programs efficiency, I took out all whitespaces on the Port-number line, an voilà, it's not working anymore.... The original format in the .conf file ist just plain Portnumber=XXXX; How can I make sscanf() exclude de equal sign? I'm using it as follows:

sscanf(line, "%s = %s", parameter_name, parameter_value);   
    debug(parameter_name);
    debug(parameter_value);

and parameter_name just saves the entire line at once... I tried using

    sscanf(line, "%s %[^=]s", parameter_name, parameter_value);

to make him save the second parameter while using everything else aside the '=', but it is not working... any one have an idea? I can't seem to find a real full list of format specifier tags on the net...

cheers

لا يوجد حل صحيح

نصائح أخرى

man scanf should give you the full list of identifiers and their description.

Anyway, none of your attempts works because the first %s will eat everything until it finds a whitespace. This is the default behavior. You need to use %[^=] in the first format specifier:

sscanf(line, "%[^= ] = %s", parameter_name, parameter_value);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top