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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何在C程序中獲取當(dāng)前目錄?

如何在C程序中獲取當(dāng)前目錄?

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

4 回答

?
陪伴而非守候

TA貢獻(xiàn)1757條經(jīng)驗(yàn) 獲得超8個(gè)贊

你看過了getcwd()嗎?


#include <unistd.h>

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

簡(jiǎn)單的例子:


#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;

}


查看完整回答
反對(duì) 回復(fù) 2019-08-31
?
長風(fēng)秋雁

TA貢獻(xiàn)1757條經(jīng)驗(yàn) 獲得超7個(gè)贊

查找手冊(cè)頁getcwd。


查看完整回答
反對(duì) 回復(fù) 2019-08-31
?
瀟瀟雨雨

TA貢獻(xiàn)1833條經(jīng)驗(yàn) 獲得超4個(gè)贊

#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;

}


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

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

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