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ÓïÑÔÖеĴ«Öµ´úÂëÈçÏ£º
int change(int x,int y)
{
int temp=x;
x=y;
y=temp;
}
CÓïÑÔÖеĴ«Ö·´úÂëÈçÏ£º
int change(int *p,int *q)
{
int temp=*p;
*p=*q;
*q=temp;
}
ʹÓÃC++ÖеÄÒýÓÃÀàÐÍ´úÂëÈçÏÂ:
int change(int &x,int &y)
{
int temp=x;
x=y;
y=temp;
}
JAV ......
Ò»£® ¸ÅÊö
ÄÚ´æй©һֱÊÇÈí¼þ¿ª·¢ÈËÔ±×îÍ·´óµÄÎÊÌâÖ®Ò»£¬ÓÈÆäÏñC/C++ÕâÑù×ÔÓɶȷdz£´óµÄ±à³ÌÓïÑÔ£¬¼¸ºõÊÇÿһ¸öÓÃÆ俪·¢³öÀ´µÄÈí¼þ¶¼»á³öÏÖÄÚ´æй©µÄÇé¿ö¡£
Èç¹ûûÓÐÄÚ´æй©£¬ÊÀ½ç»òÐí»á±äµÄÃÀºÃ¡£È»¶ø£¬ÍêÈ«ÃÀºÃµÄÊÀ½çÊDz»´æÔڵģ¬ÎÒÃÇÄÜ×öµÄ¾ÍÊǾ¡Á¿ÈÃËü±äµÄ¸üÃÀ ......
»Ø¹Ë֮ǰµÄƪ·ù£¬CÓïÑÔµÄÖ÷Ì岿·Ö»ù±¾ÒѾ½éÉÜÍêÁË¡£Ö®ËùÒÔûÓнéÉÜC++µÄÏà¹ØÌØÐÔÊÇÒòΪÔÚ֮ǰµÄÎÄÕÂÖÐCºÍC++ÔÚÕâЩ·½Ã涼Óй²ÐÔ£¬ËùÒÔÔÚÃæÏò¶ÔÏó֮ǰ¡£ÎÒÃÇÏÈ°ÑÕâЩ¹²ÐÔ¸ø½éÉÜÍê¡£Ò²¾ÍÊÇ˵ÔÚ½éÉÜÃæÏò¶ÔÏó֮ǰ£¬ËùÓеÄÎÄÕ¶¼ÊÇCC++Öж¼ÄÜʹÓõġ£´ÓÕâµãÉÏÀ´¿´£¬ÏÖÔÚÕý¼«Á¦·Ü¶·ÓÚC++Õ½ÏßÉϵijõѧÕß»¹ÊǺÜÓÐÓô¦µÄ¡£
±¾Æª¼ ......
CÊä³ö¸ñʽ×ܽá ÊÕ²Ø
CÊä³ö¸ñʽ×ܽá
1 Ò»°ã¸ñʽ
printf(¸ñʽ¿ØÖÆ£¬Êä³ö±íÁУ©
ÀýÈ磺printf("i=%d,ch=%c\n",i,ch);
˵Ã÷:
(1)“¸ñʽ¿ØÖÆ”ÊÇÓÃ˫ƲºÅÀ¨ÆðÀ´µÄ×Ö·û´®£¬Ò²³Æ“ת»»¿ØÖÆ×Ö·û´®”£¬Ëü°üÀ¨Á½ÖÖÐÅÏ¢£º
&nbs ......