getuid() /用來取得執行目前程序的使用者識别碼,每個使用者都有一個唯一的數字id.uid_t就是使用者id的專有類型。相當于int
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
int main(int argc, char * argv [ ])
{
uid_t i = getuid();
printf("%d \n",i);
return 0;
}
結果為1000
fgets()函數
從指定的f中讀取1024-1個字元,或者讀到換行符時,或者讀到檔案末尾時。會停止。讀到的資料放在buf中
#include <stdio.h>
#include <string.h>
int main(int argc, char * argv [ ])
{
FILE * fp;
char string[] = "hello liuli";
char msg[20];
fp = fopen("./1test.txt","w+");
fwrite(string,strlen(string),1,fp);
fseek(fp,0,SEEK_SET);
fgets(msg,strlen(string)+1,fp);
printf("%s\n",msg);
fclose(fp);
return 0;
}
結果是列印了hello liuli
isspace()函數
判斷是否是空白字元。具體有以下幾種空白字元。
空格(’ ‘)、定位字元(’ \t ‘)、CR(’ \r ‘)、換行(’ \n ‘)、垂直定位字元(’ \v ‘)、翻頁(’ \f ')
若c為空白字元傳回非0,否則傳回0
#include <stdio.h>
#include <ctype.h>
int main(int argc, char * argv [ ])
{
char str[] = "123c $#% GD\tSP[e?\n\t\r\v\f\b";
int i;
for (i = 0; str[i] != 0; i++)
{
if(isspace(str[i]))
printf("str[%d] is a white-space character:%d\n",i,str[i]);
}
return 0;
}
str[4] is a white-space character:32//空格
str[8] is a white-space character:32//空格
str[11] is a white-space character:9//\t
str[17] is a white-space character:10//\n
str[18] is a white-space character:9//\t
str[19] is a white-space character:13//\r
str[20] is a white-space character:11//\v
str[21] is a white-space character:12//\f
strcasecmp()函數。兩者相等 傳回0.前面的大于後面的。傳回>0.後面的大于前面的傳回<0。
用來比較大小。忽略大小寫。
#include <stdio.h>
#include <strings.h>
int main(int argc, char * argv [ ])
{
char *a = "aBcDeF";
char *b = "AbCdEf";
if(!strcasecmp(a,b))
{
printf("%s = %s\n",a,b);
}
return 0;
}
結果:aBcDeF = AbCdEf