我有以下代码,但我需要将路径与文件名连接以创建完整路径。我是C新手,我只听说过sprintf功能。有任何想法吗?谢谢!
typedef enum{
KeyFileRes_NewKeyFound,
KeyFileRes_NoKeyFound
} eKeyFileRes;
#pragma pack(push)
#pragma pack(1)
typedef struct
{
char Key[50];
int KeyLen;
} KeyStorage;
#pragma pack(pop)
eKeyFileRes GetNewKeyFile(char *path, UINT64 filename, KeyStorage keyStorage)
{
char *Fullpath;
FILE* file = fopen(Fullpath, "r");
if(file == NULL) {
return KeyFileRes_NoKeyFound;
}
else {
char c;
while((c = fgetc(file)) != EOF) {
keyStorage.Key[c];
}
keyStorage.KeyLen = sizeof(keyStorage.Key);
}
return KeyFileRes_NewKeyFound;
}
答案 0 :(得分:0)
char sbuf[1024];
sprintf (sbuf, "%s/%s", pathName, fileName);
答案 1 :(得分:0)
使用string.h
和函数strcat()
来连接两个字符串(这里是字符数组),可以帮助您简化操作