[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [CPROG] Oprettelse af en .rc fil



In article <sslug@sslug> you wrote:

> Jeg udvikler på et program som nu skal udvides med en .rc fil. Hermed
> mener jeg en fil hvori man kan skrive configurations options i stil med
> smb.conf:

> option=text
> option2=text2
> osv.

Jeg lavede en del C++ templates/biblioteker tl en mere avanceret udgave.
Men i C kan man ofte komme langt med sscanf .
Fjern selv overflødife blanktegn i var og val.


#include <stdio.h>

#define BUFFERLEN 512
#define VARLEN 30
#define VALLEN 80

int main()
{
  char lnbuf[BUFFERLEN];
  char var[VARLEN+1];
  char val[VALLEN+1];
  char dummy[1];
  int n;
  while ( fgets(lnbuf,BUFFERLEN,stdin) ) {
     *dummy='\0';
     if ((n=sscanf(lnbuf,"%30[a-zA-Z]=%80[^\n]",var,val))<2) 
	n=sscanf(lnbuf,"%30[a-zA-Z]%*[^=]=%80[^\n]",var,val);
     printf("*%d [%s] = [%s]\n",n,var,val);
  }
  return 0;
}



-- 
mvh Frank Damgaard  | http://home3.inet.tele.dk/frda/



 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:08 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *