首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

在不知道桌面文件路径的情况上,是否能使用C建立一个文件

2012-08-08 
在不知道桌面文件路径的情况下,是否能使用C建立一个文件由于每个人的电脑的桌面路径不一样,有的设置了自己

在不知道桌面文件路径的情况下,是否能使用C建立一个文件
由于每个人的电脑的桌面路径不一样,有的设置了自己名字,有的是XP有的是WIN7,他们的桌面路径不同,怎么样才能设置成功
#include <stdio.h>
main()
{
FILE *fp;
fp=fopen("C:\\Users\\Lenovo(不一样)\\Desktop\\6.txt","w");
fclose(fp); 
}



[解决办法]
用环境变量HOMEPATH,再加上Desktop
[解决办法]

C/C++ code
#include <stdio.h>#include <stdlib.h>#include <string.h>int main(void){    FILE *fp;    int i;    char pathname[128];    char userprofile[64];    strcpy(userprofile, getenv("userprofile"));    for (i = 0; userprofile[i] != '\0'; i++) {        if (userprofile[i] != '\\')            pathname[i] = userprofile[i];        else {            pathname[i+1] = userprofile[i];            pathname[i] = '\\';        }    }    pathname[i] = '\0';    strcat(pathname, "\\\\桌面\\\\6.txt");    fp = fopen(pathname, "w");    fclose(fp);    return 0;}
[解决办法]
SHGetFolderPath
[解决办法]
探讨

引用:
C/C++ code

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
FILE *fp;
int i;
char pathname[128];
char userprofile[64];
strcpy(userprofile, ……

……

热点排行