C语言函数—qsort

函数名

putw

功 能

把一字符或字送到流中

用 法

int putw(int w, FILE *stream);

程序例

#include <stdio.h> 
#include <stdlib.h> 

#define FNAME "test.$$$" 

int main(void) 
{ 
   FILE *fp; 
   int word; 

   /* place the word in a file */ 
   fp = fopen(FNAME, "wb"); 
   if (fp == NULL) 
   { 
      printf("Error opening file %sn", FNAME); 
      exit(1); 
   } 

   word = 94; 
   putw(word,fp); 
   if (ferror(fp)) 
       printf("Error writing to filen"); 
   else 
       printf("Successful writen"); 
   fclose(fp); 

   /* reopen the file */ 
   fp = fopen(FNAME, "rb"); 
   if (fp == NULL) 
   { 
      printf("Error opening file %sn", FNAME); 
      exit(1); 
   } 

   /* extract the word */ 
   word = getw(fp); 
   if (ferror(fp)) 
       printf("Error reading filen"); 
   else 
       printf("Successful read: word = %dn", word); 

   /* clean up */ 
   fclose(fp); 
   unlink(FNAME); 

   return 0; 
} 

如果引用本站的原创文章,请注明原文链接:,本站保留追究责任的权利!
评论已关闭。