The C Programming Language 经典代码 any(s1,s2)
/*
* Exercise 2-5 Page 48
*
* Write the function any(s1,s2), which returns the first location
* in the string s1 where any character from the string s2 occurs,
* or -1 if s1 contains no characters from s2. (The standard library
* function strpbrk does the same job but returns a pointer to the
* location.)
*
*/
Here's a much better solution, by Partha Seetala. This solution has a worst-
case time complexity of only O(n + m) which is considerably better.
相关文档:
简述C和C++程序员学习历程
收藏
< type="text/javascript">
document.body.oncopy = function() {
if (window.clipboardData) {
setTimeout(function() {
......
C版本:
vim stash.h
#ifndef STASH_H
#define STASH_H
typedef struct STASHTag {
int size; /* Size of each space */
int quantity; /* Number of storage spaces */
int next; /* Next empty space */
/* Dynamically allocated array of bytes: */
unsigned char* ......
一、基本知识
指针和引用的声明方式:
声明指针: char* pc;
声明引用: char c = 'A'
char& rc = c;
它们的区别:
①从现象上看,指针在运行时可以改变其所指向的值,而引用一旦和某个对象绑定后 ......
什么是空指针常量(null pointer constant)?
[6.3.2.3-3] An integer constant expression with the value 0, or such an expression cast to type void *, is called a null pointer constant.
这里告诉我们:0、0L、'\0'、3 - 3、0 * 17 (它们都是“integer constant expression”)以及 (void*)0 等都是空 ......
如果C++调用一个C语言编写的.DLL时,当包括.DLL的头文件或声明接口函数时,应加extern "C" { }。
如:
头文件cExample.h
#include <stdio.h>
#ifndef C_EXAMPLE_H
#define C_EXAMPLE_H
int add(int x,int y);
#endif
函数实现文件cExample.c(注意是.c文件)
#include<stdio.h>
#include "cExample ......