How to cut part of a string in c?

后端 未结 6 1828
面向向阳花
面向向阳花 2021-02-14 19:22

I\'m trying to figure out how to cut part of a string in C. For example you have this character string \"The dog died because a car hit him while it was crossing the road\" how

6条回答
  •  情书的邮戳
    2021-02-14 19:56

    strstr would be perfect for you, if you know the contents of the string.

    Example:

    char *str = "A dog died because a car hit him while he was crossing the road.";
    char *pCh = strstr(str, "dog");
    

    pCh will have the address of the 'd' in "dog".

提交回复
热议问题