- 论坛徽章:
- 0
|
我把substr()改成如下(substr()为取子字符串函数).还是不行.
- #include <stdio.h>;
- #include <stdlib.h>;
- char * substr();
- main()
- {
- static char AAA[]="12345678";
- static char BBB[]="654321";
- static char CCC[]="1x2x3x4x5x6x7x8x9xAxBx";
- static char DDD[]="美国好莱坞市奥斯卡街二十九号";
- printf("|%4s|",substr(AAA,0,4));
- printf("%6s|",substr(BBB,0,6));
- printf("%13s|",substr(CCC,0,13));
- printf("%18s|\n",substr(DDD,0,18));
- printf("|%4s|%6s|%13s|%18s|\n",substr(AAA,0,4),substr(BBB,0,6),substr(CCC,0,13),substr(DDD,0,18) );
- }
- char * substr(char *source_string, int start_pos, int target_string_len)
- {
- char target_string[81];
- // memset(target_string,0x0,sizeof(target_string));
- strncpy(target_string,source_string,target_string_len);
- return (target_string);
- }
复制代码
前面4个printf运行正常. |
|