Trisurf Monte Carlo simulator
Samo Penic
2016-05-15 a3f6b73f3f829a7abf3faa0e5e96d95200179529
commit | author | age
a97daa 1 #include<stdio.h>
SP 2 #include<stdlib.h>
3 #include<string.h>
4 int main(int argv, char *argc[]){
5
6
7     char *commands, *backup, *saveptr, *saveopptr, *command, *operator[2], *operand;
8     int i,j;
9     if(argv!=2){
10         fprintf(stderr, "Error. Usage: parsecmdline cmd1=1,cmd2=2,...\n");
11         exit(1);
12     }
7b0c07 13     commands=(char *)malloc(10000*sizeof(char));
SP 14     backup=commands;
a97daa 15     strcpy(commands,argc[1]);
SP 16     
17
18
19     for(i=0; ;i++, commands=NULL){
20         //breaks comma separated list of commands into specific commands.
21         command=strtok_r(commands,",",&saveptr);    
22         if(command==NULL) break;
23         fprintf(stdout,"Command %d: %s\n",i,command);    
24         //extracts name of command and value of command into operator[2] array.
25         for(j=0; j<2;j++,command=NULL){
26             operator[j]=strtok_r(command,"=",&saveopptr);
27             if(operator[j]==NULL) break;
28             fprintf(stdout," ---> Operator %d: %s\n",j,operator[j]);        
29         }
30         //1. check: must have 2 operators.
31         if(j!=2) fprintf(stderr,"Error. Command no. %d is not formatted properly.\n",i);
32         //2. check: must be named properly.
33         //3. check: must be of right format (integer, double, string, ...)
34
35
36     }
37
38     free(backup);
7b0c07 39     return 0;
a97daa 40 }