From 52feef3369ad80d5b7207620f37ae341ccd11b95 Mon Sep 17 00:00:00 2001 From: =?utf8?q?M=C3=A5rten=20Dolk?= Date: Thu, 19 May 2005 13:30:24 +0000 Subject: [PATCH] intital ci of simprog.c --- simprog.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 simprog.c diff --git a/simprog.c b/simprog.c new file mode 100644 index 0000000..a713847 --- /dev/null +++ b/simprog.c @@ -0,0 +1,72 @@ +#include +#include +#include + + +void print_help(char name[]) +{ + printf("\n"); + printf("Simulates execution of an program. \n"); + printf("\n"); + printf("Usage: %s \n", name); + printf("The default action of the program is to return with 0 (success) \n"); + printf(" -eNN=MM Return with value NN with a probability of MM% \n"); + printf("\n"); +} + + +void parse_argv(char argv[], int *retval, int *percentage) +{ + if ( sscanf(argv,"-e %d = %d",retval,percentage)!=2 ) + { + printf("Argument sytax error : %s \n", argv); + exit(EXIT_FAILURE); + } + + if ( *percentage <= 0 ) + { + printf("Percentage argument must be > 0"); + exit(EXIT_FAILURE); + } +} + + + +int main (int argc, char** argv) +{ + int i, rand_value, sum; + int retvals[100]; + int percentages[100]; + + if (argc==2 && strcmp("--help",argv[1])==0 ) + { + print_help(argv[0]); + return 1; + } + + + for (i=1; i