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

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文件中引用CPP文件时的问题


unzip.c
中引用validate.cpp
文件中的函数来进行epub
纠错,产生的问题:
1.    
validate.cpp
中使用iostream.h,
但是C
中没有这个文件
,所以产生的错误:
2>
正在编译...
2>unzip.c
2>D:\Program
Files\VC\include\cstdio(25) : error C2143:
语法错误:
缺少“{ ......

VC .NET中String^ 与ANSI C char*互转

VC.NET中的String类是利用Unicode字符集编码来表示文本。Unicode字符集中每个字符(汉字、英文字母)都占2个字节,且其字符串是以2个连续的\0结尾的。
ANSI的ASCII字符集是最常见的字符集,常用于表示txt的文本文件。在ASCII字符集中英文占一个字节,汉字2个字节,且其字符串是以一个\0结尾的。
在利用VC.NET进行混合编程时 ......

zz Emacs C

日期:2009-11-21   10:54:22
本节主要参考:
    曹乐的《在Emacs下用C/C++编程》
    王纯业的《Emacs 一个强大的平台》
    emacswiki.org
emcas难学易用,可扩展性强。有人把她当作信仰,有人认为他是魔鬼!学习首先记住基本的键盘快捷键,学会常用插件, ......

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

C程序是由一组或是变量或是函数的外部对象组成的。 函数是一个自我包含的完成一定相关功能的执行代码段。下面小编和大家分享下C语言中的函数。
1.       ldexp函数
ldexp函数的功能是计算value*2的幂,其用法为:double ldexp(double value, int exp);程序实例如下:
    ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号