第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在C程序中獲取當前目錄?

如何在C程序中獲取當前目錄?

C
慕桂英546537 2019-08-31 14:38:41
我正在制作一個C程序,我需要從中獲取程序啟動的目錄。該程序是為UNIX計算機編寫的。我一直在尋找opendir()和telldir(),但telldir()返回off_t (long int),所以它確實沒有幫助我。如何在字符串(char數(shù)組)中獲取當前路徑?
查看完整描述

4 回答

?
陪伴而非守候

TA貢獻1757條經(jīng)驗 獲得超8個贊

你看過了getcwd()嗎?


#include <unistd.h>

char *getcwd(char *buf, size_t size);

簡單的例子:


#include <unistd.h>

#include <stdio.h>

#include <limits.h>


int main() {

   char cwd[PATH_MAX];

   if (getcwd(cwd, sizeof(cwd)) != NULL) {

       printf("Current working dir: %s\n", cwd);

   } else {

       perror("getcwd() error");

       return 1;

   }

   return 0;

}


查看完整回答
反對 回復 2019-08-31
?
長風秋雁

TA貢獻1757條經(jīng)驗 獲得超7個贊

查找手冊頁getcwd。


查看完整回答
反對 回復 2019-08-31
?
瀟瀟雨雨

TA貢獻1833條經(jīng)驗 獲得超4個贊

#include <stdio.h>  /* defines FILENAME_MAX */

//#define WINDOWS  /* uncomment this line to use it for windows.*/

#ifdef WINDOWS

#include <direct.h>

#define GetCurrentDir _getcwd

#else

#include <unistd.h>

#define GetCurrentDir getcwd

#endif


int main(){

  char buff[FILENAME_MAX];

  GetCurrentDir( buff, FILENAME_MAX );

  printf("Current working dir: %s\n", buff);

  return 1;

}


查看完整回答
反對 回復 2019-08-31
  • 4 回答
  • 0 關(guān)注
  • 1011 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號