首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

C语言中在Linux下建立临时文件编译不通过,该怎么处理

2012-05-20 
C语言中在Linux下建立临时文件编译不通过#include stdio.h#include stdlib.h/*包含头文件。*/main(){ex

C语言中在Linux下建立临时文件编译不通过
#include <stdio.h> 
#include <stdlib.h> /*包含头文件。*/ 
main() 
{  
  extern int errno; /*设置一个错误号。*/ 
  char path[]="mytemp-XXXXXX"; /*定义文件名。*/ 
   
  if(mkstemp(path)!=-1) /*建立一个临时文件。*/ 
  { 
  printf("created temp file %s.\n",path); /*显示文件已经建立。*/ 
  } 
  else /*另一种情况。*/ 
  { 
  printf("cant't create temp file %s.\n",path); /*显示不能创建临时文件。*/ 
  printf("errno:%d\n",errno); /*显示错误号。*/ 
  printf("ERR :%s\n",strerror(errno)); /*显示错误信息。*/ 
  } 
}  

运行环境ubuntu11.04自代GCC , 编译不通过。


[解决办法]
#include <string.h>
#include <errno.h>
#include <error.h>

请包涵上门的头文件即可。
[解决办法]

C/C++ code
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <errno.h>int main(int argc, char* const argv[]) {        char template[] = "mytemp-XXXXXX";        int fd = mkstemp(template);        if (fd == -1) {                perror("mkstemp:");                return -1;        }        close(fd);        return 0;} 

热点排行