相关疑难解决方法(0)

fopen()中r +和w +之间的差异

fopen("myfile", "r+")什么之间的区别"r+""w+"开放模式?我看了这个:

"r" 打开文本文件进行阅读.
"w"打开文本文件以进行写入,将现有文件截断为零长度,或者创建文件(如果该文件不存在).

"r+"打开文本文件进行更新(即读取和写入).
"w+"打开文本文件以进行更新(读取和写入),首先将文件截断为零长度(如果存在)或创建文件(如果文件不存在).

我的意思是不同的是,如果我打开文件"w+",文件将被删除?

c fopen

48
推荐指数
5
解决办法
12万
查看次数

C - 创建/写入/读取命名管道

我想创建一个命名管道,然后写入它,然后我想读取它。这是我的代码:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <string.h>
#include <fcntl.h>
#define FIFO "fifo0001"
int main(intargc, char *argv[]){
    char input[256];
    FILE *fp;
    char str[50];
    printf("Please write some text:\n");
    scanf("%s", input);
    unlink(FIFO); /* Because it already exists, unlink it before */
    umask(0);
    if(mkfifo(FIFO, 0666) == -1){
        printf("Something went wrong");
        return EXIT_FAILURE;
    }
    if((fp = fopen(FIFO, "a")) == NULL){
        printf("Something went wrong");
        return EXIT_FAILURE;
    }
    fprintf(fp, "%s", input);
    if(fgets(str, 50, fp) != NULL){
        puts(str);
    }
    fclose(fp); …
Run Code Online (Sandbox Code Playgroud)

c fopen file pipe fifo

3
推荐指数
1
解决办法
8032
查看次数

标签 统计

c ×2

fopen ×2

fifo ×1

file ×1

pipe ×1