By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,640 Members | 2,279 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,640 IT Pros & Developers. It's quick & easy.

help me please

P: 25
Expand|Select|Wrap|Line Numbers
  1.  
  2. // File name: command.c
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <stdlib.h>
  6.  
  7. int main (int argc, char *argv[])
  8.  
  9. {
  10. int i;
  11. double minx = -1.0;
  12. double maxx = 1.0;
  13. double miny = -1.0;
  14. double maxy = 1.0;
  15. double scale = 1.0;
  16. double zmax = 999;
  17.  
  18. for (i=1;i< argc;i++)
  19.     {
  20.     if (strcmp(argv[i],"-range") == 0)
  21.         {
  22.             if (argc <= 6)
  23.                 {
  24.                                  if(atof(argv[i+1]) < atof(argv[i+2]) && atof(argv[i+3]) < atof(argv[i+4]))
  25.                               {
  26.                     minx = atof(argv[++i]);
  27.                             maxx = atof(argv[++i]);
  28.                             miny = atof(argv[++i]);
  29.                             maxy = atof(argv[++i]);
  30.                             }
  31.                         else
  32.                     {
  33.                             printf("Error\n");
  34.                     }
  35.             else
  36.                 {
  37.                 printf("There must be four values specified\n");
  38.                 }
  39.         }
  40.     else if (strcmp(argv[i],"-scale") == 0)
  41.         {
  42.         if (argc <= 3)
  43.             {
  44.             scale = atof(argv[++i]);
  45.             }
  46.         else
  47.             {
  48.             printf("Please specify new scale value\n");
  49.             }
  50.         }
  51.     else if (strcmp(argv[i],"-m") == 0)
  52.         {
  53.         zmax = zmax * 1000.0;
  54.     else
  55.         {
  56.         printf("%s is invalid argument\n",argv[i]);
  57.         exit(0);
  58.         }
  59.     }
  60. printf("x is from %lf to %lf, y is from %lf to %lf\n",minx, maxx, miny, maxy);
  61. printf("scale is %lf\n", scale);
  62. printf("z max is %lf\n",zmax);
  63. }
  64.  
Well, the code above works as I want, but I still have to add some conditions:
1. Why if I compile and I do not enter four values it is not working, for example:
cc command.c
a.out -range 1 2 3
2. Same thing, but this for the -scale case, for example:
cc command.c
a.out -scale
3. This is the most tedious task for me, how do I stop the program if after -range there are four correct values are specified, but then after -scale no new scale value is specified, example:
cc command.c
a.out -range 1 2 3 4 -m -scale
4. Same like no 3 but this time the scale value is specified, but range is not specified, example:
cc command.c
a.out -scale 2 -m -range 2 3 4
5. How do I stop the program and display ALL invalid arguments. I am only able to display one invalid argument if I use exit

Thanks
Sep 14 '06 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.