the dest_cust structure. Notice that, just as with strcpy(), the
destination comes first. * /
memcpy(&dest_cust, &src_cust, sizeof(CUSTREC));
printf("Done! I just copied customer number # %d (%s %s). " ,
dest_cust. id, dest_cust. first_name, dest_cust. last_name) ;
}
请参见:
6.6 怎样拷贝字符串的一部分?
6.7 怎样打印字符串的一部分?
6. 2 怎样删去字符串尾部的空格?
。
C 语言没有提供可删去字符串尾部空格的标准库函数,但是,编写这样的一个函数是
很方便的。请看下例:
#include <stdio. h>
# include <string. h>
void main (void);
char * rtrim(char * );
void main(void)
{
char * trail_str = "This string has trailing spaces in it";
/ * Show the status of the string before calling the rtrim()
function. * /
printf("Before calling rtrim(), trail_str is '%s'\fi" , trail_str);
print ("and has a length of %d. \n" , strlen (trail_str));
/ * Call the rtrimO function to remove the trailing blanks. * /
rtrim(trail_str) ;
/ * Show the status of the string
after calling the rtrim() function. * /
2006-6-7 12:41
回复
210.77.88.* 2 楼
printf("After calling rttim(), trail_ str is '%s'\n", trail _ str );
printf ("and has a length of %d. \n" , strlen(trail-str)) ;
}
/ * The rtrim() function removes trailing spaces from a string. * /.
char * rtrim(char * str)
{
int n = strlen(str)-1; / * Start at the character BEFORE
the null character (\0). * /
while (n>0) / * Make sure we don't go out of hounds. . . * /
{
if ( * (str + n) 1 =' ') / * If we find a nonspace character: * /
{