Error[8]: Undefined offset: 5, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

C Programming/Pointers and arrays - Wikibooks, open books for an open world

Pointers and Text Strings

Historically, text strings in C have been implemented as arrays of characters, with the last byte in the string being a zero, or the null character '\0'. Most C implementations come with a standard library of functions for manipulating strings. Many of the more commonly used functions expect the strings to be null terminated strings of characters. To use these functions requires the inclusion of the standard C header file "string.h".

A statically declared, initialized string would look similar to the following:

static const char *myFormat = "Total Amount Due: %d";

The variable myFormat can be viewed as an array of 21 characters. There is an implied null character ('\0') tacked on to the end of the string after the 'd' as the 21st item in the array. You can also initialize the individual characters of the array as follows:

static const char myFlower[] = { 'P', 'e', 't', 'u', 'n', 'i', 'a', '
static const char *myColors[] = {
   "Red", "Orange", "Yellow", "Green", "Blue", "Violet" };
' };

An initialized array of strings would typically be done as follows:

static char *longString = "Hello. My name is Rudolph and I work as a reindeer "
  "around Christmas time up at the North Pole.  My boss is a really swell guy."
  " He likes to give everybody gifts.";

The initilization of an especially long string can be split across lines of source code as follows.

[+++]



The library functions that are used with strings are discussed in a later chapter.

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 165, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Pointers and Text Strings_随笔_内存溢出

Pointers and Text Strings

Pointers and Text Strings,第1张

C Programming/Pointers and arrays - Wikibooks, open books for an open world

Pointers and Text Strings

Historically, text strings in C have been implemented as arrays of characters, with the last byte in the string being a zero, or the null character '\0'. Most C implementations come with a standard library of functions for manipulating strings. Many of the more commonly used functions expect the strings to be null terminated strings of characters. To use these functions requires the inclusion of the standard C header file "string.h".

A statically declared, initialized string would look similar to the following:

static const char *myFormat = "Total Amount Due: %d";

The variable myFormat can be viewed as an array of 21 characters. There is an implied null character ('\0') tacked on to the end of the string after the 'd' as the 21st item in the array. You can also initialize the individual characters of the array as follows:

static const char myFlower[] = { 'P', 'e', 't', 'u', 'n', 'i', 'a', '
static const char *myColors[] = {
   "Red", "Orange", "Yellow", "Green", "Blue", "Violet" };
' };

An initialized array of strings would typically be done as follows:

static char *longString = "Hello. My name is Rudolph and I work as a reindeer "
  "around Christmas time up at the North Pole.  My boss is a really swell guy."
  " He likes to give everybody gifts.";

The initilization of an especially long string can be split across lines of source code as follows.



The library functions that are used with strings are discussed in a later chapter.

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/2084784.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-07-22
下一篇 2022-07-22

发表评论

登录后才能评论

评论列表(0条)

保存