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:
![](https://i-blog.csdnimg.cn/blog_migrate/cbef093dcc044b2793832001e2365e43.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/cbef093dcc044b2793832001e2365e43.gif)
#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!
![](https://i-blog.csdnimg.cn/blog_migrate/cbef093dcc044b2793832001e2365e43.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/cbef093dcc044b2793832001e2365e43.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/918e8df969f9f8c8d002f25cda86cade.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/cbef093dcc044b2793832001e2365e43.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/cbef093dcc044b2793832001e2365e43.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/cbef093dcc044b2793832001e2365e43.gif)
The following code uses sprintf() to convert an integer into a string of characters:
![](https://i-blog.csdnimg.cn/blog_migrate/cbef093dcc044b2793832001e2365e43.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/cbef093dcc044b2793832001e2365e43.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/cbef093dcc044b2793832001e2365e43.gif)
This code is similar, except that it converts a floating-point number into an array of characters:
![](https://i-blog.csdnimg.cn/blog_migrate/cbef093dcc044b2793832001e2365e43.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/cbef093dcc044b2793832001e2365e43.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/cbef093dcc044b2793832001e2365e43.gif)
snprintf() is like sprintf but with length argument!
(continuing...)