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
}
方法一:当前工程下的文件
fopen("demo.txt","rt")
方法二:当前工程下的 test文件夹 中文件
fopen(".\\test\\demo.txt","rt")
方法三:绝对路径,D盘下project文件夹中的文件
fopen("d:\\project\\demo.txt","rt")
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)