c语言获取当前项目路径的文件

c语言获取当前项目路径的文件,第1张

/*从字段山携符串的左边截取n个字符*/

char * left(char *dst,char *src, long n)

{

    char *p = src

    char *q = dst

    int len = strlen(src)

    if(n>len) n = len

    /*p += (len-n)*/  /*从右边第n个字符开始*/

    while(n--) *(q++) = *(p++)

    *(q++)='\0'/*有必要吗?很有必要*/

    return dst

}

int substr(char *s1, char *s2)

{

    char *s3 = strstr(s1,s2)

    if(s3 == NULL)

          return -1

    return strlen(s1)-strlen(s3)

}

char* mysubstr(char* srcstr, int offset, int length) {

    int total_length = strlen(srcstr)

    int real_length = ((total_length - offset) >= length ? length : (total_length - offset)) + 1

    char *tmp

    if (NULL == (tmp=(char*) malloc(real_length * sizeof(char)))) {

     握伏   printf("Memory overflow . \n")

        exit(0)

    }

    strncpy(tmp, srcstr+offset, real_length - 1)

    tmp[real_length - 1] = '\0'

    return tmp

}

#define ENCODE 1

#define IN_PCM(a) strcat(a,"/file/input.pcm")

#define OUT_SPX(a) strcat(a,"/file/out.spx")

#define OUT_PCM(a) strcat(a,"/file/out.pcm")

int main(int argc, char **argv){

    char* path

    char* dist

    path = argv[0]

    char* index =  strstr(path,PROJECT_PATH)

    long diff = index-path

    char *pathDir = mysubstr(path,0,substr(path,PROJECT_PATH)+9)

    // 创建一个字符串数组

    char arr1[64] = {0}

    strcpy(arr1, pathDir)

    char arr2[64] = {0}

    strcpy(arr2, pathDir)

    char* temp0=IN_PCM(pathDir)

    char* temp=OUT_SPX(arr1)

    char* tempOut=OUT_PCM(arr2)

    // 创建一个字符串数组

    char arr0[64] = {0}

    strcpy(arr0, temp0)

    printf("唯迟after arr0=%s\n,arr1=%s\n,arr2=%s\n",arr0,arr1,arr2)

    return 0

}

http://hi.baidu.com/andywangcn/item/7633efda5517baf9ca0c39c6

获得双斜杠路径不包含文件名春肆

TCHAR _szPath[MAX_PATH + 1]={0}

GetModuleFileName(NULL, _szPath, MAX_PATH)

(_tcsrchr(_szPath, _T('\\')))[1] = 0//删除文件名,只获得路径 字串

CString strPath

for (int n=0_szPath[n]n++)

{

if (_szPath[n]!=_T('\\'))

{

strPath +=_szPath[n]

}

else

{

strPath += _T("\\\\")

}

}

MessageBox(strPath)//输出==e:\\program\\Debug\扒败轿\

/枯散/头文件用到 windows.h


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/tougao/8199611.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-14
下一篇 2023-04-14

发表评论

登录后才能评论

评论列表(0条)

保存