我是C编程的新手。 我有这个问题,我不明白。看起来windows下的字符串是以完全不同的方式处理的,为什么呢?字符串处理C linux和windows
吴丹是我的代码
#include <stdio.h>
#include <string.h> // compare strings
void addextname(char *str1, char *str2, char *nome1){
int i,j;
i = 0;
while (str1[i]!='.') {
nome1[i] = str1[i];
i++;
}
j = 0;
while (str2[j]!='\0') {
nome1[i] = str2[j];
i++;
j++;
}
}
int main()
{
char str1[9]="file.stl";
char str2[9]="name.stl";
int len1 = strlen(str1);
int len2 = strlen(str2);
char nome1[len1+len2+1];
addextname(str1,str2,nome1);
printf("%s %s %s\n",str1,str2,nome1);
return 0;
}
我的目的是要读它的扩展名(.STL)中输入文件名和一些字符添加到它保持该扩展。在Linux下,我没有问题,在Windows下,输出文件名被保存不正确。 我的编译行是
gcc modstr.c -std=c99 -o strings
我真的很感激一个问题的答案!
@桥你编辑过哪一行,因为代码看起来像前一个 – Nicholas 2012-01-17 09:29:23
括号中的缩进问题,它将代码块分成两个单独的代码块。只是为了更好的格式:) – qiao 2012-01-17 09:32:43
@乔耶!我认为这是我的代码上的东西,但我后来发现答案是: – Nicholas 2012-01-17 09:54:24