2009年2月19日 星期四

typedef 語法

typedef int MYINT; <== 必需加分號,否則編譯會錯

-> define MYINT as int

Example:

int main()
{
MYINT var;
}

2009年2月18日 星期三

測試檔案是否存在

c library中有access函式可以用來測試檔案的狀況。

Example:

#include <unistd.h>
int main(){

int r = access("a.txt", F_OK);
if(r==-1)
printf("File doesn't exist.\n");
else
printf("File exists.\n");

}


參考網址:
http://www.gnu.org/software/libtool/manual/libc/Testing-File-Access.html

test2

tet