我有一个char给出的fgets,我想知道如何将它转换为char*.
我确信之前已经发布过,但我找不到一个我想做的事情.任何答案都表示赞赏.
编辑:这是代码.
char *filename = "file.txt";
FILE *file = fopen(filename, "r");
if(file != NULL) {
char line[260];
char *fl;
while(fgets(line, sizeof line, file) != NULL) {
// here I combine some strings with the 'line' variable.
str_replace(line, "\"", "\"\""); // A custom function, but it only takes char*'s.
}
printf(fl);
printf("\n");
} else {
printf(" -- *ERROR* Couldn't open file.\n");
}
Run Code Online (Sandbox Code Playgroud) 我知道可能有类似的问题,它只是在C++中,我不知道它们是否相同.我有一些代码
void BuildApp(char *AppName)
{
char *cmd;
cmd = combine("mkdir ./Projects/", AppName);
cmd = combine(cmd, "/Package/");
// Make the package dir.
system(cmd);
cmd = "";
cmd = combine("mkdir ./Projects/", AppName);
cmd = combine(cmd, "/Package/DEBIAN");
system(cmd);
cmd = "";
cmd = combine("mkdir ./Projects/", AppName);
cmd = combine(cmd, "/Package/Applications");
system(cmd);
cmd = "";
cmd = combine("mkdir ./Projects/", AppName);
cmd = combine(cmd, "/Package/Applications/");
cmd = combine(cmd, AppName);
cmd = combine(cmd, ".app");
system(cmd);
cmd = "";
cmd = combine("mkdir ./Projects/", AppName);
cmd = combine(cmd, …Run Code Online (Sandbox Code Playgroud)