• This topic is empty.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • #178
    admin
    Keymaster

      int main(int argc, string argv[])
      {
      ./caesar = argv[0];

      With argv[0], I intend to make sure that this performs ./caesar command when entered through command line interface.

      Kindly guide how to correct as the above code showing error while compiling.


      Reply


      You don’t need to make sure that your program starts with “./caesar” … if the user starts the program with something else, then your program simply will not start 🙂

      But comparing two strings can be done with strcmp(), check how to use in the manual pages: https://manual.cs50.io/. You cannot compare two strings with ‘==’, you will learn later why not.

      Also, a string needs to be enclosed in ” …”


      Query


      Okay, understood that not to include ./caesar = argv[0] for argv[0].

      But not clear what then I should include for argv[0].


      Reply


      You don’t include anything for argv[0]. It will always be the name of the program. It will be ./caesar (or the absolute path to it) unless the user renames the executable and there’s no reason to prevent them from doing that.


      Query


      Okay, then no need to include argv[0] as part of the main body.

      [learn_press_profile]

    Viewing 1 post (of 1 total)
    • You must be logged in to reply to this topic.
    Scroll to Top