#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