我正在使用一个简单的“C”代码来执行以下操作:
1) 从 .txt 文件中读取。
2) 根据 .txt 文件中的字符串,将创建一个目录。
我无法执行第 2 步,因为我不清楚类型转换。
这是我的代码:
#include <stdio.h>
#include <stdlib.h>
#include <direct.h>
int main()
{
char ch, file_name[25];
FILE *fp;
//printf("Enter the name of file you wish to see\n");
//gets(file_name);
fp = fopen("input.txt","r"); // read mode
if( fp == NULL )
{
perror("Error while opening the file.\n");
exit(EXIT_FAILURE);
}
printf("The contents of %s file are :\n", file_name);
while( ( ch = fgetc(fp) ) != EOF )
printf("%c",ch);
if( _mkdir(ch ) == 0 )
{
printf( "Directory successfully created\n" );
printf("\n");
}
fclose(fp);
return 0;
}
这是错误:
*error #2140: Type error in argument 1 to '_mkdir'; expected 'const char *' but found 'char'.*