Together talk C Chestnut Bar (73rd back: C language Instance--diy pwd command)

Source: Internet
Author: User

Ladies and gentlemen, crossing, the last time we were talking about DIY date command example, this time we say the example is:DIY pwd command . Gossip Hugh, words return to the positive. Let's talk C chestnuts together!

Crossing, when you switch directories frequently, there is a feeling that you do not know which directory you are in, and you need to use the PWD command to show which directory you are currently in. Today, we come together to DIY the PWD command.

Here are the steps to the DIY pwd command:

    • 1. Use the GETCWD function to get the current path;
    • 2. Output the path obtained in step 1.

Below is the code of our DIY pwd command, please refer to:

int pwds(){    char buf[PATH_SIZE];    *res;    res = getcwd(buf,PATH_SIZE);    if(res)    {        printf("%s\n",buf);        return0;    }    else        return1;}

Relatively speaking, the program is relatively simple. But there are some caveats, and let's emphasize that:
When using the GETCWD function, you need a large enough memory space to hold the acquired path. If the space is not large enough, it is possible to obtain a failure, so we need to determine the execution result of the function and confirm whether the current path can be displayed by the result.

Crossing, the text does not write code, the detailed code put in my resources, you can click here to download the use.

Here is the result of the program running:


Below is the operation result of the PWD command in the system, please compare with the above results:


You crossing, the example of the DIY pwd command we're going to talk about here. I want to know what the following example, and listen to tell.

Together talk C Chestnut Bar (73rd back: C language Instance--diy pwd command)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.