File: test_parser.c

package info (click to toggle)
c2x 2.35a%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,020 kB
  • sloc: ansic: 19,816; makefile: 54; sh: 1
file content (34 lines) | stat: -rw-r--r-- 571 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/* Command-line routine to check arithmetic parser in c2x
 *
 * compile with "gcc test_parser.c parse.c -lm"
 */

#include<stdio.h>
#include<stdlib.h>

int ascan(char *in, double *result);
int debug;

int main(int argc, char **argv){
  double x;
  char *test;
  size_t i,n;
  
  test=NULL; n=0;
  debug=6;
  
  printf("Please input line to parse and evaluate: ");
  i=getline(&test,&n,stdin);
  test[i-1]=0; /* Remove newline */
  
  ascan(test,&x);

  printf("Final result: %f\n",x);
}

void error_exit(char *msg){
  fprintf(stderr,"Aborting: %s\n",msg);
  exit(1);
}