登录 | 首页 -> 华新鲜事 -> 社会百科 | 切换到:传统版 / sForum | 树形列表
C programming 问题
<<始页  [1]  末页>> 

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.
[香蕉 (3-29 19:48, Long long ago)] [ 传统版 | sForum ][登录后回复]1楼

rephraze ur question a bitstrsep
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'

[chancing (3-29 23:30, Long long ago)] [ 传统版 | sForum ][登录后回复]2楼

(引用 chancing:rephraze ur question a bitstrsep Syntax #include char *strsep(char **stringp, char *delim); Description This function retriev...)more info available hereclick[chancing (3-29 23:31, Long long ago)] [ 传统版 | sForum ][登录后回复]3楼

如果没理解错你的问题,你可以这样做char * sString = "if gcc a.out";
char * sSubString = sString + 3;

++++++++++++++++++++++++++++++++++
sSubString不就是你想要的嘛。
[鱽鳓 (3-30 10:29, Long long ago)] [ 传统版 | sForum ][登录后回复]4楼


<<始页  [1]  末页>> 
登录 | 首页 -> 华新鲜事 -> 社会百科 | [刷新本页] | 切换到:传统版 / sForum