[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: [PROGRAMMERING] [c] Læse fil med tre kolonner



donald_j_axel <sslug@sslug> wrote in  
> Hvorfor bruger du ikke Linux C++, d.v.s. GNU C++, som er ret god?
> Evt. med noget kdevelop eller sourcenavigator?

Det skal også kunne køre på wintendo.

> 
> Hvis du ikke skriver din egen input parser (brug evt. regex eller
> lex/yacc) så kan du enten bruge
> 
>    1) sscanf(3) (prøv at undgå scanf(3))
> 
>    2) strtof(3) og/eller strtod(3)
> 
>    3) atof(3), en wrapper for strtof(3)

Jeg vil helst undgå c++ commandoer.

Jeg har prøvet flg. men der printes intet. Hvad kan der være galt?

  FILE *fp;
  char *text;
  float MW[MAX_COMPONENTS];
  float w[MAX_COMPONENTS];
  float Tc[MAX_COMPONENTS];
  float Pc[MAX_COMPONENTS];
  int i=0;
  fp = fopen(argv[1],"r");
  if (!fp) {
    sprintf(errormsg, "Kan ikke åbne fil ved navn %s",argv[1]);
    error(errormsg,2);
  }
  for (i=0;i<MAX_COMPONENTS;i++) {
    while 
(fscanf(fp,"%s\t%f\t%f\t%f\t\n",*text,&MW[i],&w[i],&Tc[i],&Pc[i])) {
      printf("Molekyle:%s, MW:%5.2f Omega:%5.2f Tc:%5.2f 
Pc:%5.2f\n",*text,MW[i],w[i],Tc[i],Pc[i]);
    }
  }

og her er min inputfil:

CH4 72.15 0.252 469.7 33.7
C2H6  86.177  0.301 507.6 30.25
C6  100 -1  -1  -1

MVH,
CHristian Wix



 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 22:43 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] *