C programming 问题
登录 | 论坛导航 -> 华新鲜事 -> 社会百科 | 本帖共有 4 楼,分 1 页, 当前显示第 1 页 : 本帖树形列表 : 刷新 : 返回上一页
<<始页  [1]  末页>>
作者:香蕉 (等级:5 - 略有小成,发帖:971) 发表:2004-03-29 19:48:49  楼主  关注此帖
C programming 问题
if now i have a string "if gcc a.out"
how to transfer this string into "gcc a.out", which means delete the substring"if ".


thanks for advice.




哥哥,收我做你的迷~~~~~
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版只看此人从这里展开收起列表
作者:chancing (等级:3 - 略知一二,发帖:750) 发表:2004-03-29 23:30:32  2楼
rephraze ur question a bit
strsep
Syntax
#include <string.h>

char *strsep(char **stringp, char *delim);

Description
This function retrieves the next token from the given string, where stringp points to a variable holding, initially, the start of the string. Tokens are delimited by a character from delim. Each time the function is called, it returns a pointer to the next token, and sets *stringp to the next spot to check, or NULL.

Return Value
The next token, or NULL.

Portability
not ANSI, not POSIX

Example
main()
{
char *buf = "Hello there,stranger";
char **bp = &buf;
char *tok;
while (tok = strsep(bp, " ,"))
printf("tok = `%s'\n", tok);
}

tok = `Hello'
tok = `'
tok = `there'
tok = `stranger'

欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版只看此人从这里展开收起列表
作者:chancing (等级:3 - 略知一二,发帖:750) 发表:2004-03-29 23:31:09  3楼
rephraze ur question a bitstrsep Syntax #include char *strsep(char **stringp, char *delim); Description This function retrieves the next token from the given string, where stringp points to a variable holding, initially, the start of the string. Tokens are delimited by a character from delim. Each time the function is called, it returns a pointer to the next token, and sets *stringp to the next spot to check, or NULL. Return Value The next token, or NULL. Portability not ANSI, not POSIX Example main() { char *buf = "Hello there,stranger"; char **bp = &buf; char *tok; while (tok = strsep(bp, " ,")) printf("tok = `%s'\n", tok); } tok = `Hello' tok = `' tok = `there' tok = `stranger'
more info available here
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版只看此人从这里展开收起列表
作者:鱽鳓 (等级:2 - 初出茅庐,发帖:259) 发表:2004-03-30 10:29:14  4楼
如果没理解错你的问题,你可以这样做
char * sString = "if gcc a.out";
char * sSubString = sString + 3;

++++++++++++++++++++++++++++++++++
sSubString不就是你想要的嘛。
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版只看此人从这里展开收起列表
论坛导航 -> 华新鲜事 -> 社会百科 | 返回上一页 | 本主题共有 4 篇文章,分 1 页, 当前显示第 1 页 | 回到顶部
<<始页  [1]  末页>>

请登录后回复:帐号   密码