APUE学习笔记

Alex posted @ 2011年8月21日 21:49 in c/cpp , 1523 阅读

 

  1 #include <stdio.h>
  2 #include <stdlib.h>
  3 #include <dirent.h>
  4
  5 int main(int argc,char *argv[])
  6 {
  7     DIR *dp;
  8     struct dirent *dirp;
  9
 10     if(argc != 2)
 11         printf("err argument");
 12
 13     if((dp = opendir(argv[1])) == NULL)
 14         printf("can't open %s",argv[1]);
 15
 16     while((dirp = readdir(dp)) != NULL)
 17         printf("%s\n", dirp->d_name);
 18
 19     closedir(dp);
 20     exit(0);
 21 }

 

 

  1 #include "stdio.h"
  2 #include "apue.h"
  3 
  4 int main(void)
  5 {
  6     int c;
  7     while((c=getc(stdin))!=EOF)
  8         if(putc(c,stdout)==EOF)
  9             printf("output error");
 10 
 11     if(ferror(stdin))
 12         printf("input error");
 13 
 14     exit(0);
 15 }
~          
 
 
wucy@wucy-laptop:~/app$ vim fig1.4.c
 
  1 #include "apue.h"
  2 int main(void)
  3 {
  4     printf("hello world from proces ID %d\n",getpid());
  5     exit(0);
  6 }
 
wucy@wucy-laptop:~/app$ gcc -o fig.1.4 fig1.4.c
wucy@wucy-laptop:~/app$ ./fig.1.4 
hello world from proces ID 1933
wucy@wucy-laptop:~/app$ ./fig.1.4 
hello world from proces ID 1934
wucy@wucy-laptop:~/app$ ./fig.1.4 
hello world from proces ID 1935
wucy@wucy-laptop:~/app$ 
 

登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter