C/C++——小编谈C语言函数那些事(13)
	
    
    
	C程序是由一组或是变量或是函数的外部对象组成的。 函数是一个自我包含的完成一定相关功能的执行代码段。下面小编和大家分享下C语言中的函数。
1.       malloc函数
malloc函数的功能是内存分配函数,其用法为:void *malloc(unsigned size);程序实例如下:
#include <stdio.h>
#include <string.h>
#include <alloc.h>
#include <process.h>
int main(void)
{
   char *str;
      if ((str = malloc(10)) == NULL)
   {
      printf("Not enough memory to allocate buffer\n");
      exit(1);  /* terminate program if out of memory */
   }
    strcpy(str, "Hello");
    printf("String is %s\n", str);
    free(str);
    return 0;
}
 
2.      memchr函数
memchr函数的功能是在数组的前n个字节中搜索字符,其用法为:void *memchr(void *s, char ch, unsigned n);  程序实例代码如下:
#include <string.h>
#include <stdio.h>
int main(void)
{
   char str[17];
   char *ptr;
   strcpy(str, "This is a string");
   ptr = memchr(str, 'r', strlen(str));
   if (ptr)
      printf("The character 'r' is at position: %d\n", ptr - str);
   else
      printf("The character was not found\n");
   return 0;
}
3.      memicmp函数
memicmp函数的功能是比较两个串s1和s2的前n个字节, 忽略大小写,其用法为:int memicmp(void *s1, void *s2, unsigned n);程序实例代码如下:
#include <stdio.h>
#include <string.h>
int main(void)
{
   char *buf1 = "ABCDE123";
   char *buf2 = "abcde456";
   int stat;
   stat = memicmp(buf1, buf2, 5);
   printf("The strings to position 5 are ");
   if (stat)
   printf("not ");
 &
    
     
	
	
    
    
	相关文档:
        
    
    C程序是由一组或是变量或是函数的外部对象组成的。 函数是一个自我包含的完成一定相关功能的执行代码段。下面小编和大家分享下C语言中的函数。
 
1. kbhit函数
 
kbhit函数是检查当前按下的键,其用法为:int kbhit(void);程序例子如下:
#include <conio.h>
int main(void)
{
   c ......
	
    
        
    
    系统环境:Windows 7
软件环境:Visual C++ 2008 SP1 +SQL Server 2005
本次目的:编写一个航空管理系统
      这是数据库课程设计的成果,虽然成绩不佳,但是作为我用VC++ 以来编写的最大程序还是传到网上,以供参考。用VC++ 做数据库设计并不容易,但也不是不可能。以下是我的程序界面,后面 ......
	
    
        
    
     
#ifndef _PPC_BOOT_STRING_H_
#define _PPC_BOOT_STRING_H_
#include <stddef.h>
extern char *strcpy(char *dest, const char *src);
extern char *strncpy(char *dest, const char *src, size_t n);
extern char *strcat(char *dest, const char *src);
extern int strcmp(const char *s1, const cha ......
	
    
        
    
    C程序是由一组或是变量或是函数的外部对象组成的。 函数是一个自我包含的完成一定相关功能的执行代码段。下面小编和大家分享下C语言中的函数。
1.       ldexp函数
ldexp函数的功能是计算value*2的幂,其用法为:double ldexp(double value, int exp);程序实例如下:
     ......