我想char array="some text" 在文件中写一个字符数组 ,这是最简单的写入方式C.实际上我正在编写一个设备驱动程序,所以我必须在C中为设备驱动程序编写代码.从用户空间我必须读取一个数组来自用户空间的字符,也在内核空间写一个字符数组,但我是C的新手,这就是我问这个问题的原因.
// Char arrays are declared like so:
char array[] = "YOUR TEXT HERE";
// Open a file for writing.
// (This will replace any existing file. Use "w+" for appending)
FILE *file = fopen("filename", "w");
int results = fputs(array, file);
if (results == EOF) {
// Failed to write do error code here.
}
fclose(file);
Run Code Online (Sandbox Code Playgroud)
编辑:
有fputs倒退的论点.
fputs不返回写入的字节数.只是一个错误代码.