设为首页 加入收藏

TOP

void*alloca()中不懂的
2014-11-23 22:51:34 】 浏览:376
Tags:void alloca

  请看这个例子:


  FILE *open_err_file( char *name )
  {
   char *buffer;
   /* allocate temporary buffer for file name */
   buffer = (char *)alloca( strlen( name ) + 5 );
   if( buffer ) {
   FILE *fp;
   sprintf( buffer, "%s.err", name );
   fp = fopen( buffer, "w" );
   return fp;
   }
   return (FILE *)NULL;
  }
  int main( void )
  {
   FILE *fp;
   if((fp = open_err_file( "err_name" ))<0) {
   printf( "Unable to open error file\n" );
   return(1);
   } else {
   fprintf( fp, "Hello from the alloca test.\n" );
   fclose( fp );
   }
   return EXIT_SUCCESS;
  }


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇怎么删除一个非空的目录? 下一篇获取本机的本地上网IP地址

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目