Chinaunix首页 | 论坛 | 博客
  • 博客访问: 15340105
  • 博文数量: 2005
  • 博客积分: 11986
  • 博客等级: 上将
  • 技术积分: 22535
  • 用 户 组: 普通用户
  • 注册时间: 2007-05-17 13:56
文章分类

全部博文(2005)

文章存档

2014年(2)

2013年(2)

2012年(16)

2011年(66)

2010年(368)

2009年(743)

2008年(491)

2007年(317)

分类:

2010-05-18 09:51:50

#include
#include
#include
#include

void str2pixel(void *string, char delim, void *width, void *height)
{
    char *path=strdup(string);
    char *pname;
    char *pt,*pp,*pf;

    pname = rindex(path, '/');

    if (pname == NULL)
        pname = path;
    else ++pname;

    pt = strchr(pname, delim);

    if (pt) {
        *pt = 0;

        pp = pt - 1;
        while (isdigit(pp[-1])) --pp;
        pf = pt + 1;
        while (isdigit(pf[0])) ++pf;
        *pf = 0;
        pf = pt + 1;

        if (!(pp && pf)) {
            pp = pf = "";
        }
    } else {
        pp = pf = "";
    }
   
    if (width) strcpy(width, pp);
    if (height) strcpy(height, pf);

    free(path);
}

int main(void)
{
    char *path="/vobs/123/abc_800x600slasd.bmp";
    char width[64];
    char height[64];

    str2pixel(path, 'x', width, height);

    printf("0x%02x - %s\n", width[0], width);
    printf("0x%02x - %s\n", height[0], height);
}
阅读(1460) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~