易截截图软件、单文件、免安装、纯绿色、仅160KB

C/C++——小编谈C语言函数那些事(16)

 C程序是由一组或是变量或是函数的外部对象组成的。 函数是一个自我包含的完成一定相关功能的执行代码段。下面小编和大家分享下C语言中的函数。
1.      qsort函数
qsort函数的功能是使用快速排序例程进行排序,其用法为:void qsort(void *base, int nelem, int width, int (*fcmp)());程序实例如下:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int sort_function( const void *a, const void *b);
char list[5][4] = { "cat", "car", "cab", "cap", "can" };
 
int main(void)
{
   int  x;
   qsort((void *)list, 5, sizeof(list[0]), sort_function);
   for (x = 0; x < 5; x++)
      printf("%s\n", list[x]);
   return 0;
}
int sort_function( const void *a, const void *b)
{
   return( strcmp(a,b) );
}
 
2.      putw函数
putw函数的功能是把一字符或字送到流中,其用法为int putw(int w, FILE *stream);程序实例代码如下:
#include <stdio.h>
#include <stdlib.h>
#define FNAME "test.$$$"
int main(void)
{
   FILE *fp;
   int word;
   fp = fopen(FNAME, "wb");
   if (fp == NULL)
   {
      printf("Error opening file %s\n", FNAME);
      exit(1);
   }
   word = 94;
   putw(word,fp);
   if (ferror(fp))
       printf("Error writing to file\n");
   else
       printf("Successful write\n");
   fclose(fp);
   fp = fopen(FNAME, "rb");
   if (fp == NULL)
   {
      printf("Error opening file %s\n", FNAME);
      exit(1);
   }
   word = getw(fp);
   if (ferror(fp))
       printf("Error reading file\n");
   else
 &nbs


相关文档:

航空公司管理系统(VC++ 与SQL 2005)

系统环境:Windows 7
软件环境:Visual C++ 2008 SP1 +SQL Server 2005
本次目的:编写一个航空管理系统
      这是数据库课程设计的成果,虽然成绩不佳,但是作为我用VC++ 以来编写的最大程序还是传到网上,以供参考。用VC++ 做数据库设计并不容易,但也不是不可能。以下是我的程序界面,后面 ......

Hidden Tricks (C)(091121)

 请运行下面的代码,观察结果,有人说怎么是死循环,你同意吗?为什么?
 
#include
 <stdio.h>
int
 main()
{
  int
 i = 0;
  int
 name[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; ......

C/C++——小编谈C语言函数那些事(13)

C程序是由一组或是变量或是函数的外部对象组成的。 函数是一个自我包含的完成一定相关功能的执行代码段。下面小编和大家分享下C语言中的函数。
1.       malloc函数
malloc函数的功能是内存分配函数,其用法为:void *malloc(unsigned size);程序实例如下:
#include <stdio.h>
#i ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号