include stdio include string define icon_no const char ICON_NO int get

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <stdio.h>
#include <string.h>
#define icon_no -
const char ICON_NO[] = "-";
int get_description(char * filename, int argc, char * argv[], char* result) {
char * ext_pnt = strrchr(filename,'.');
if(!ext_pnt)
return 0;
char * ext = &ext_pnt[1];
int i;
for ( i = 1; i< argc ; i++ ) {
char * arg = argv[i];
int extlen = strlen(ext);
if( strncmp(ext,arg,extlen) == 0 ) {
strcpy(result,&arg[extlen+1]);
return 1;
}
printf("arg[%d]=%s, result: %s\n", i, arg, result);
}
strcpy(result,ICON_NO);
strcat(result,ext_pnt);
return 0;
}
char TEST_FILENAME[] = "test.rar.xpng";
//intputargs extension=description extension=descrtiption
int main(int argc, char * argv[] ) {
char result[128];
char * desc = get_description(TEST_FILENAME, argc,argv,&result);
printf("result=%s\n",result);
return 0;
}