STRING.CPP
资源名称:C++100.rar [点击查看]
上传用户:wszmarenbt
上传日期:2013-04-26
资源大小:2552k
文件大小:1k
源码类别:
Windows编程
开发平台:
Visual C++
- #include <stdio.h>
- #include <conio.h>
- #include <string.h>
- char *COPY(char *TARGET,char *SOURCE);
- char *REVERSE(char *STRING);
- int GETLEN(char *STRING);
- int main(void)
- {
- char STRING1[]="TO TEST THE FUNCTIONS OF STRING";
- char STRING2[32];
- char STRING3[]="I LOVE THE COMPUTER";
- printf("nSTRING1[]=%s",STRING1);
- printf("nTHE LENGTH OF STRING1=%d",GETLEN(STRING1));
- COPY(STRING2,STRING1);
- printf("nnAFTER COPYING STRING2[]=%sn",STRING2);
- printf("nBEFORE REVERSE STRING3[]=%sn",STRING3);
- REVERSE(STRING3);
- printf("nAFTER REVERSING STRING3[]=%sn",STRING3);
- getch();
- return 0;
- }
- char *COPY(char *TARGET,char *SOURCE)
- {
- char *STR1,*STR2;
- STR1=SOURCE;
- STR2=TARGET;
- while (*STR1!=' ')
- {
- *STR2=*STR1;
- STR1++;
- STR2++;
- }
- *STR2=' ';
- return TARGET;
- }
- char *REVERSE(char *STRING)
- {
- char *STR1,*STR2;
- char YUAN[32];
- COPY(YUAN,STRING);
- STR1=YUAN+strlen(YUAN)-1;
- STR2=STRING;
- while (*STR2!=' ')
- {
- *STR2=*STR1;
- STR1--;
- STR2++;
- }
- return STRING;
- }
- int GETLEN(char *STRING)
- {
- int NUM=0;
- while(*STRING!=' ')
- {
- NUM++;
- STRING++;
- }
- return NUM;
- }