String processing is very important in programming! How to express string semantic ?
There are many methods with doing it! Some are listed below!
(1) char array and pointer.
This is always used in c. The advantage is high time efficiency,beause it manipulate memory address directly! However it produce errors very easily and isn't very convenient! Some tips may be helpful!
#const string definition:
const char *str="hello" or
const char str[]="hello"
#string definition:
char str[LEN]; //LEN is compling-time const!
char *str=new char[ILEN] //LEN is valid value!
but don't forget delete []str;
#functions which relate to string, definined in string.h/stdio.h etc
such as:
strcmp,strlen,strcpy/strncpy etc! please refer to
http://www.cppreference.com/stdstring/index.html
some function is worth learning! Attention please!
sprintf() is useful!
#include <stdio.h>
int sprintf( char *buffer, const char *format, );
char string[50];
sprintf( string, "Hello %s",world );
The following code uses sprintf() to convert an integer into a string of characters:
char result[100];
int num = 24;
sprintf( result, "%d", num );
This code is similar, except that it converts a floating-point number into an array of characters:
char result[100];
int num = 24;
sprintf( result, "%d", num );
snprintf() is like sprintf but with length argument!
(continuing...)