小编Man*_*ruz的帖子

如何用C编辑txt文件的特定行

我目前正在尝试在 C 中编辑 .txt 文件的特定行。我使用的文件如下所示:

像素位置和 RGB 颜色

现在假设我想更改图像上突出显示的特定行上所写的内容:

400,300:(255,255,255)#FFFFFF

进入这个:

400,300: (000,000,000) #000000

基本上,我试图在特定像素上创建一个黑点,在本例中是 400,300。这就是我的代码:

#include <stdio.h>
int main(void)
{
    const char *filename = "sample.txt";
    int x = 400;
    int y = 300;

    FILE *fp;
    fp = fopen(filename, "w+");

    // Algorithm that reads all the file

    // If("Operation that reads" == x+","+y)
    // {
    //     Replace the line information after where it starts with "400,300"
    //     Like this : 400,300: (000,000,000) #000000
    // }


    // Algorithm that saves the …
Run Code Online (Sandbox Code Playgroud)

c io file edit

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

c ×1

edit ×1

file ×1

io ×1