代码大全

(singke) #1
CONSTANT+1 C

n n+1
0


CONSTANT+1 CONSTANT
/ Declare the string to have length of "constant+1"
Every other place in the program "constant" rather
than"constant+1"is used.
/


char string[NAME_LENGTH+1]; /* string of length NAME_LENGTH */
NAME_LENGTH+l

/* Example 1: Set the string to all 'A's using the constant.
NAME_LENGTH as the number of 'A's that can be copied.
Note that NAME_LENGTH rather than NAME_LENGTH+1 is used. */

for(i=0;i<NAME_LENGTH;i++) NAME_LENGTH
string[ i ]='A';

/* Example2:Copy another string into the first string using
the constant as the maximum length that can be copied. */

strcpy(string some_other_string NAME_LENGTH);

NAME_LENGTH
NAME_LENGTH-1 NAME_LENGTH+1
NAME_LENGTH


0 C

0 C

0

0

:

char EventName[MAX_NAME_LENGTH+1]={0};
calloc( ) malloc( ) 0 calloc( )

Free download pdf