Menu

would you please help me figure this simple c

2002-11-23
2012-09-26
  • Nobody/Anonymous

    would you please explain why did the prof use
    x[i-1]=atof(argv[i]) in this program.
    and what does argc, and argv mean in this progaram. 

    #include <iostream>
    #include <stdlib.h>
    double findSmallLarge(int , double *, double &);
    double findSmallLarge(int np, double x[], double &big)
    {
        double smallest = x[0];
        for (int i = 1; i < np; i++)
          
            if (smallest > x[i])
                smallest = x[i];
        big = x[0];
        for (int i = 1; i < np; i++)
            if (big < x[i])
                big = x[i];
        return smallest;
    }

    int main(int argc, char *argv[])
    {
      double x[50];
      for (int i = 1; i < argc; i++)
        x[i-1] = atof(argv[i]);
      double smallest, biggest;
      smallest = findSmallLarge(argc - 1, x, biggest); 
      cout << smallest << "  " << biggest << endl;
      system("PAUSE");   
      return 0;
    }

     
    • Nobody/Anonymous

      About argc and argv:

      if you go to dos and try to:
      scandisk C: /parameter1 /parameter2
      then
      argc=4 and argv[0]=scandisk, argv[1]=c:, argv[2]=/parameter1, argv[3]=/parameter2

      About the other part i dont know, cause i dont know c++ and looking through a ANSI C perspective, it seems all wrong :)

       
    • Nobody/Anonymous

      thank you very much, that helped..........

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.