- 論壇徽章:
- 95
|
原帖由 sunceenjoy 于 2007-7-3 10:59 發(fā)表
3. strcat的用法不對,man strcat
老兄,為什么strcat用法不對呢,3個不都是指針嗎
strcat(3) 用法示例:
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define nelem(a) (sizeof(a)/sizeof(a[0]))
- int main()
- {
- unsigned int i;
- char *Filepath = "c:\\windows\\";
- int Filepath_len = strlen(Filepath);
- char *tempuser;
- char *user[3] = {"user1","user2","user3"};
- for(i=0;i<nelem(user);i++)
- {
- tempuser = malloc(Filepath_len + strlen(user[i]) + 1);
- if(tempuser == NULL)
- exit(1);
- strcat(tempuser, Filepath);
- strcat(tempuser, user[i]);
- printf("%s\n",tempuser);
- free(tempuser);
- }
- return 0;
- }
復制代碼 |
|