c/c++ string
1.本章思维导图:
Example1:
char
*strcpy(char *target, const char *source) {
char *t = target;
// Copy the contents of source into target.
while(*source) *target++ = *source++;
// Null-terminate the
target.
*target = '\0';
// Return pointer to the
start of target.
return t;
}
Example2:
void
*memmove(void *target, const void *source, size_t count)
这个函数即使
是在源和目的字符串有所重叠时操作也能成功,虽然source为const,但是其指向的array也可能被修改。
2.
C型字符串操作实例:
Ex1.基本操作
/*
*
=====================================================================================
*
* Filename: 2-1.cpp
*
*
Description: Fundamental Operations in C Type String
*
*
Version: 1.0
* Created: 05/11/2010 10:43:11 AM
*
Revision: none
* Compiler: gcc
*
*
Author: gnuhpc (http://blog.csdn.net/gnuhpc)
,
warmbupt@gmail.com
* Company: IBM CDL
*
*
=====================================================================================
*/
#include
#include
using namespace std;
int main(int argc, char *argv[])
{
char strA[7]="UP";
char strB[5]="DOWN";
char strC[5]="LEFT";
char strD[6]="RIGHT";
/*Display */
cout << "Here are the strings: " <<
endl;
相关文档:
总是被同学们问到,如何学习C和C++才不茫然,才不是乱学,想了一下,这里给出一个总的回复。
一家之言,欢迎拍砖哈。
1、可以考虑先学习C。
大多数时候,我们学习语言的目的,不是为了成为一个语言专家,而是希望成为一个解决问题的专家。做一个有用的程序员,做一个赚钱的程序员。我们的价值,将体现在客户价值上,而不 ......
C、传统 C++
#include <stdio.h> //定义输入/输出函数
#include <stdlib.h> //定义杂项函数及内存分配函数
#include <string.h> //字符串处理
#include <assert.h> //设定插入点
#include <ctype.h> //字符处理
#include <errno.h&g ......
当尝试从文件读入字符时,getc()函数会返回EOF,所以程序会在下一次读取时才会发现文件结尾。此时程序在试图读取空文件,可能会发生一些问题。所以应当在循环入口处进行判断。
int ch;
FILE * fp;
fp = fopen ("test","r");
while ((ch = getc(fp) != EOF)
{
putchar (ch);
} ......
引言
最近笔者一直在做JPEG的解码工作,发现用完全使用哈夫曼树进行解码比较费时,而使用表结构存储编码和值的对应关系比较快捷,但是也存在比较难处理的地方,比如解码工作通常是以位为单位的操作,这里必然会涉及到移位操作,而笔者之前对位的操作很少,经验很欠缺,经过这次历练终于发现了一个自己曾经忽视的东西,那就 ......