Linux C gets the current working directory

Source: Internet
Author: User
#include <stdio.h> #include <string.h> #include <unistd.h>int main (void) {char buffer[1024];// To get the current working directory, note: The length must be greater than the length of the working directory plus one char *p = GETCWD (buffer, +), char *dir = null;printf ("buffer:%s   p:%s size:%d  \ n", b  Uffer, p, strlen (buffer));//Gets the name of the current working directory DIR = (char *) get_current_dir_name ();p rintf ("dir:%s \ n", dir); char *twd = NULL; TWD = GETWD (buffer);p rintf ("buffer:%s   twd:%s \ n", buffer, TWD); return 0;}

Operation Result:

Buffer:p: (NULL) size:0
Dir:/mnt/sdb1/yangyx/system system programming/File directory interface and sound card implementation
Buffer:/mnt/sdb1/yangyx/system system programming/File directory interface and sound card implementation Twd:/mnt/sdb1/yangyx/system system programming/File directory interface and sound card implementation

Linux C gets the current working directory

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: info-contact@alibabacloud.com 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.