Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you want to use <code>scanf</code> you could just allocate a large enough buffer to hold any possible value, say 1024 bytes, then use a maximum field width specifier of 1024.</p> <p>The <code>m</code> and <code>a</code> are specific non-standard GNU extensions, so thats why Microsofts compiler does not support them. One could wish that visual studio did.</p> <p>Here is an example using <code>scanf</code> to read settings, and just print them back out:</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;errno.h&gt; #include &lt;malloc.h&gt; int main( int argc, char **argv ) { // usage ./a.out &lt; settings.conf char *varname; int value, r, run = 1; varname = malloc( 1024 ); // clear errno errno = 0; while( run ) { // match any number of "variable = #number" and do some "processing" // the 1024 here is the maximum field width specifier. r = scanf ( "%1024s = %d", varname, &amp;value ); if( r == 2 ) { // matched both string and number printf( " Variable %s is set to %d \n", varname, value ); } else { // it did not, either there was an error in which case errno was // set or we are out of variables to match if( errno != 0 ) { // an error has ocurred. perror("scanf"); } run = 0; } } return 0; } </code></pre> <p>Here is an example <code>settings.conf</code></p> <pre><code>cake = 5 three = 3 answertolifeuniverseandeverything = 42 charcoal = -12 </code></pre> <p>You can read more about <a href="http://www.kernel.org/doc/man-pages/online/pages/man3/scanf.3.html" rel="nofollow noreferrer" title="man 3 scanf"><code>scanf</code> on the manpages</a>.</p> <p>And you can of course use <code>getline()</code>, and after that parse character after character.</p> <p>If you would go into a little more what you are trying to achieve you could maybe get an better answer.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload