• Skip to main content
  • Skip to footer

CS50's Introduction to Computer Science on Edx: Supplementary resource

CS50 threads to aide as a supplementary resource

How to denote ./caesar with argv[0]

CS50 threads to aide as a supplementary resource › Forums › CS50’s Introduction to Computer Science by Harvard University on Edx › Week 2 › How to denote ./caesar with argv[0]

Tagged: Caesar project, command line interface in c

  • This topic is empty.
Log In Register Lost Password
Viewing 1 post (of 1 total)
  • Author
    Posts
  • January 31, 2022 at 11:26 am #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]

    • Author
      Posts
    Log In Register Lost Password
    Viewing 1 post (of 1 total)
    • You must be logged in to reply to this topic.
    Log In

    Log in / Register

    Initiative by Digital Splendid OPC Pvt. Ltd.