易截截图软件、单文件、免安装、纯绿色、仅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/C++——小编谈C语言函数那些事(9)

C程序是由一组或是变量或是函数的外部对象组成的。 函数是一个自我包含的完成一定相关功能的执行代码段。下面小编和大家分享下C语言中的函数。
1.     harderr函数
harderr函数的功能是建立一个硬件错误处理程序,其用法是:void harderr(int (*fptr)());程序例子如下:
#include <stdio.h>
......

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:
语法错误:
缺少“{ ......

zz Emacs C

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

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}; ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号