From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id FAA23510; Sun, 18 Apr 2004 05:59:21 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id FAA22623 for ; Sun, 18 Apr 2004 05:59:20 +0200 (MET DST) Received: from hotmail.com (bay7-f39.bay7.hotmail.com [64.4.11.39]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i3I3xIYM023163 for ; Sun, 18 Apr 2004 05:59:19 +0200 Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; Sat, 17 Apr 2004 20:59:17 -0700 Received: from 66.141.17.195 by by7fd.bay7.hotmail.msn.com with HTTP; Sun, 18 Apr 2004 03:59:17 GMT X-Originating-IP: [66.141.17.195] X-Originating-Email: [writetosafi@hotmail.com] X-Sender: writetosafi@hotmail.com From: "mohammad siddiqui" To: skaller@users.sourceforge.net Cc: rich@annexia.org, caml-list@inria.fr Subject: [Caml-list] sscanf help Date: Sun, 18 Apr 2004 03:59:17 +0000 Mime-Version: 1.0 Content-Type: text/plain; format=flowed Message-ID: X-OriginalArrivalTime: 18 Apr 2004 03:59:17.0910 (UTC) FILETIME=[858A3360:01C424F9] X-Miltered: at concorde by Joe's j-chkmail ("http://j-chkmail.ensmp.fr")! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; sscanf:01 sscanf:01 fscanf:01 clue:01 char:01 char:01 isspace:01 isspace:01 printf:01 qid:99 printf:01 ocaml:01 int:01 int:01 eof:02 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hello, I am having hardtime dealing with sscanf and fscanf fucntion. I am actually converting code from C to OCAML. The functions uses multiple sscanf fucntions. I have no clue how to deal with this. Can anyone please help me out? Attached is the function in C. The application is used for text classification. i nt parse_document(char *line, DOC *doc, double *label, long int *numwords, long int max_words_doc) { register long wpos,pos; long wnum; double weight; int numread; char featurepair[1000],junk[1000]; doc->queryid=0; doc->costfactor=1; pos=0; while(line[pos]) { /* cut off comments */ if(line[pos] == '#') { line[pos]=0; } else { pos++; } } wpos=0; if(sscanf(line,"%lf",label) == EOF) return(0); pos=0; while(isspace((int)line[pos])) pos++; while((!isspace((int)line[pos])) && line[pos]) pos++; while(((numread=sscanf(line+pos,"%s",featurepair)) != EOF) && (wposqueryid=(long)wnum; } else if(sscanf(featurepair,"cost:%lf%s",&weight,junk)==1) { /* it is the example-dependent cost factor */ doc->costfactor=(double)weight; } else if(sscanf(featurepair,"%ld:%lf%s",&wnum,&weight,junk)==2) { /* it is a regular feature */ if(wnum<=0) { perror ("Feature numbers must be larger or equal to 1!!!\n"); printf("LINE: %s\n",line); exit (1); } if((wpos>0) && ((doc->words[wpos-1]).wnum >= wnum)) { perror ("Features must be in increasing order!!!\n"); printf("LINE: %s\n",line); exit (1); } (doc->words[wpos]).wnum=wnum; (doc->words[wpos]).weight=(FVAL)weight; wpos++; } else { perror ("Cannot parse feature/value pair!!!\n"); printf("'%s' in LINE: %s\n",featurepair,line); exit (1); } } (doc->words[wpos]).wnum=0; (*numwords)=wpos+1; doc->docnum=-1; doc->twonorm_sq=sprod_ss(doc->words,doc->words); return(1); } thanks, Mohammad S Siddiqui. _________________________________________________________________ MSN Toolbar provides one-click access to Hotmail from any Web page – FREE download! http://toolbar.msn.com/go/onm00200413ave/direct/01/ ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners