Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to get parameter from file? 1

Status
Not open for further replies.

allan76

Technical User
Sep 24, 2003
1
CN
Hi

I want get parameter from file,Parameters are supposed to be identified with an =, The left part of the "=" is the identifier, and the right part the value.There are several "parameter=" tags in a file.
Please let me know if you know of some way.
thanks.

Allan76
 
Well here's one way

Code:
#include <stdio.h>
#include <string.h>

int main ( int argc, char * argv[]) {
    char buff[BUFSIZ],param[BUFSIZ],value[BUFSIZ];
    FILE *fp = fopen(&quot;tmp&quot;,&quot;r&quot;);
    while ( fgets(buff,BUFSIZ,fp) ) {
        if ( sscanf( buff, &quot;%[^=]=%[^\n]&quot;, param, value ) == 2 ) {
            printf( &quot;Found p=%s, v=%s\n&quot;, param, value );
        } else {
            printf( &quot;Bad line = %s\n&quot;, buff );
        }
    }
    fclose( fp );
    return 0;
}

--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top