jinyedge's note
{http://www.jinyedge.pe.kr}


Hi, this is jinyedge. I'm a software developer. I hope you can find some useful information in my homepage.


jinyedge at gmail.com
Since 2001.12.05

 

 
Subj Cont
 
Subj: C, Slicing substring.
Mtime: 2009-10-23 22:44:07

#include <stdio.h>
#include <string.h>
int main(){
    char buf[128];
    char* line = "Content-Type: text/html; charset=UTF-8";

    // Position of `=`.
    printf("strchr = %d, strstr = %d, strrchr = %d\n"
        , strchr(line, `=`) - line, strstr(line, "=") - line, strrchr(line, `=`) - line);

    // Using strncpy.
    int pos = strrchr(line, `=`) - line;
    if(pos >= 0){
        pos++;        // Don`t need `=`.

        memset(buf, 0, 128);
        strncpy(buf, line + pos, strlen(line) - pos);
        printf("++%s++\n", buf);
    }

    return 0;
}