当前位置:首页 » 编程博文
开发技术指南» 文章正文
    引言: 本章集中讨论字符串操作,包括拷贝字符串,拷贝字符串的一部分,比较字符串,字符串右对齐,删去字符串前后的空格,转换字符串,等等。
 

 

 ·如何下载完整的ie6sp1    »显示摘要«
    摘要:第一步:访问微软的网站,下载ie6sp1 安装文件,只有479kb的那个。第二步:建立一个文件夹c:\downloads,把第一步下载的文件拷贝到这个目录里。第三步:从开始菜单选择运行,然后键入下面命令 "c:\downloads\ie6setup.exe" /c:"ie6wzd.exe /d /s:""#e"第四部:选择一个保存安装文件......
 ·阶乘运算之python vs java    »显示摘要«
    摘要:阶乘运算,随便写一个1000!,结论大家自己去总结吧!================python版================print reduce(lambda x,y:x*y, range(1, 1001))================java版================import java.io.*;import java.math.*;public class main......


字符串操作--c语言
本章集中讨论字符串操作,包括拷贝字符串,拷贝字符串的一部分,比较字符串,字符串右对齐,删去字符串前后的空格,转换字符串,等等.c语言提供了许多用来处理字符串的标准库函数,本章将介绍其中的一部分函数.

    在编写c程序时,经常要用到处理字符串的技巧,本章提供的例子将帮助你快速学会一些常用函数的使用方法,其中的许多例子还能有效地帮助你节省编写程序的时间. 【程序编程相关:面试时最经常被问到的问题(Frenque

【推荐阅读:多硬盘操作系统的引导

【扩展信息:面试时最经常被问到的问题(Frenque

    6.1 串拷贝(strcpy)与内存拷贝(memcpy)有什么不同?它们适合于在哪种情况下使用?

    strcpy()函数只能拷贝字符串.strcpy()函数将源字符串的每个字节拷贝到目录字符串中,当遇到字符串末尾的null字符(\0)时,它会删去该字符,并结束拷贝.

    memcpy()函数可以拷贝任意类型的数据.因为并不是所有的数据都以null字符结束,所以你要为memcpy()函数指定要拷贝的字节数.

      在拷贝字符串时,通常都使用strcpy()函数;在拷贝其它数据(例如结构)时,通常都使用memcpy()函数.

    以下是一个使用strcpy()函数与memcpy()函数的例子:

#include <stdio. h>

#include <string. h>

typedef struct cust-str {

    int id ;

    char last_name [20] ;

    char first_name[l5];

} custrec;

void main (void);

void main (void)

{

    char * src_string = "this is the source string" ;

    char dest_string[50];

    custrec src_cust;

    custrec dest_cust;

    printf("hello! i´m going to copy src_string into dest_string!\n");

    / * copy src_ string into dest-string. notice that the destination

      string is the first argument. notice also that the strcpy()

      function returns a pointer to the destination string. * /

    printf("done! dest_string is: %s\n" ,

        strcpy(dest_string, src_string)) ;

    printf("encore! let´s copy one custrec to another. \n") ;

    prinft("i´ll copy src_cust into dest_cust. \n");

    / * first, intialize the src_cust data members. * /

    src_cust. id = 1 ;

    strcpy(src_cust. last_name, "strahan");

    strcpy(src_cust. first_name, "troy");

    / * now, use the memcpy() function to copy the src-cust structure to

        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. * /

    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)

{


...   下一页
 ·rms入门    »显示摘要«
    摘要: record management system是j2me的一个重要的子系统,目的是实现应用程序本地数据的持久性存储。目前支持文件系统的移动信息设备还有限,因此record management system是j2me开发人员实现本地数据存储的首选途径。本文的目的就是全面的介绍record management system的知识。 ......
» 本期热门文章:

©2000-2007 All Rights Reserved. 最佳浏览:1024X768 MSIE