GNU C Library——最全的C函数说明
前天写一个小程序, 突然发现其实偶的C学的不怎么样啊,好多函数都不记得,在网上搜到的都是些乱七八糟的,没有原型,用起来不放心,用E文搜,搜到真正的Bible——
The GNU C Library Manual
这里面太全了,只是有一点不太好,E文的,读起来有点慢,感觉有点浪费时间
用C写了段小程序把一个五笔码文本文档转为SQLite3格式的数据库
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <regex.h>
#include <sqlite3.h>
int main(int argc, char** argv)
{
sqlite3 *db = NULL;
char *zErrMsg = 0;
int rc = 0;
rc = sqlite3_open("wubi.db",&db);
if( rc )
{
fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
sqlite3_close(db);
exit(1);
}
char *sql, insert[256];
sql = "CREATE TABLE word (cn VARCHAR(3) NOT NULL, first VARCHAR(4) NOT NULL, sec VARCHAR(4), pri SMALLINT DEFAULT 0)";
sqlite3_exec( db, sql, 0, 0, &zErrMsg );
sql = "CREATE TABLE wordgroup (cn VARCHAR(12) NOT NULL, first VARCHAR(4) NOT NULL, ind SMALLINT DEFAULT 0)";
sqlite3_exec( db, sql, 0, 0, &zErrMsg );
regex_t reg ;
regmatch_t pm[1];
char *pattern;
char buf[50];
const size_t nmatch = 1;
//取得正则表达式,并进行编译
pattern = argv[1];
int result = regcomp(®, pattern, REG_EXTENDED);
//逐行读取文件
while( fgets(buf, sizeof(buf), stdin) )
{
int e = strlen(buf);
if ( e > 0 && buf[e-1] == '\n' )
buf[e-1] = 0;
result = regexec( ®, buf, nmatch, pm, REG_NOTBOL );
if ( result == REG_NOMATCH )
continue;
int i = 0;
for ( i = 0; i < nmatch && pm[i].rm_so != -1; ++i )
{
int code = e - pm[i].rm_so;
printf("字符\"%s\"的长度为:%d\n",buf, e);
char *c = NULL, *a = NULL, *b = NULL , *word = NULL ;
word = (char *)malloc( 50*sizeof(char) );
c = (char *)malloc( 50*sizeof(char) );
a = (char *)malloc( 4*sizeof(char) );
b = (char *)malloc( 4*sizeof(char) );
//取一个字符串的子字符,前半部
strncpy( word, buf, pm[i].r
相关文档:
最近对基础知识进行了学习,发现以前很多东西都没有搞清楚
1. 编译的问题,头文件主要是定义
//////// add.c
int add(int a, int b)
{
return a + b;
}
///////// main.c
#include <stdio.h>
int add(int a, int b);
int main ()
{
printf("%d" ......
这是C的原程序
#include <stdio.h>
#include <regex.h>
int main(int argc, char** argv)
{
regex_t reg;
regmatch_t pm[10];
char *pattern;
char buf[50];
const size_t nmatch = 10;
pattern = argv[1];
int result = regcomp(®, pattern, REG_EXTENDED);
while( fgets ......
#include <assert.h> //设定插入点
#include <ctype.h> //字符处理
#include <errno.h> //定义错误码
#include <float.h> //浮点数处理
#include <fstream.h> //文件输入/输出
#include  ......
C/C++ 常见误区
1. C++虽然主要是以C的基础发展起来的一门新语言,但她不是C的替代品,不是C的升级,C++和C是兄弟关系。没有谁比谁先进的说法,更重要的一点是C和C++各自的标准委员会是独立的,最新的C++标准是C++98,最新的C标准是C99。因此也没有先学C再说C++的说法,也不再(注意这个"不再")有C++语法 ......
#include<stdio.h>
#include<malloc.h>
#include<string.h>
/*
* 翻转
*/
char *mystrrev(char *arr)
{
if (!arr)
{
return NULL;
}
char *temp = arr;
char t;
int leng = strlen(arr) + 1;
int l = (int)(leng / 2);
int i = 0;
while (l--)
{
t = arr[i];
arr[ ......