标签:
环境变量
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
extern char**environ;
main(int args,char**argv,char**arge)
{
printf("%s\n",getenv("PATH"));
printf("%s\n",getenv("LOGNAME"));
/*
while(environ && *environ)
{
printf("%s\n",*environ);
environ++;
}
*/
/*
while(arge && *arge)
{
printf("%s\n",*arge);
arge++;
}
int i=0;
while(arge && arge[i])
{
printf("%s\n",arge[i++]);
}
*/
}
read &&open 函数
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
main()
{
char name[20];
int age;
float score;
char sex;
char *filename="a.dat";
int fd;
fd=open(filename,O_RDWR);
if(fd==-1)
{
perror("open error");
exit(-1);
}
int r;
while(1)
{
r=read(fd,name,sizeof(name));
if(r<=0) break;
r=read(fd,&age,sizeof(int));
r=read(fd,&score,sizeof(score));
r=read(fd,&sex,sizeof(char));
printf("%s,%d,%5.2f,%c\n",
name,age,score,sex);
}
close(fd);
}
write&&函数
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
main()
{
int fd;
char *filename="a.dat";
char name[20];
int age;
float score;
char sex;
fd=open(filename,O_RDWR|O_CREAT|O_EXCL,0666);
if(fd==-1)
{
perror("open error");
exit(-1);
}
bzero(name,sizeof(name));
//memset(name,0,sizeof(name));
memcpy(name,"tom",3);
age=20;
score=89.99f;
sex=‘m‘ ;
write(fd,name,sizeof(name));
write(fd,&age,sizeof(age));
write(fd,&score,sizeof(score));
write(fd,&sex,sizeof(sex));
bzero(name,sizeof(name));
memcpy(name,"Jack",4);
age=18;
score=99.88f;
sex=‘f‘;
write(fd,name,sizeof(name));
write(fd,&age,sizeof(age));
write(fd,&score,sizeof(score));
write(fd,&sex,sizeof(sex));
close(fd);
}
printf("%*2$.*3$f\n",12345.6789,40,20);
标签:
原文地址:http://www.cnblogs.com/x113/p/4676959.html