如何编辑用系统命令创建的C文本文件?

如何编辑用系统命令创建的C文本文件?,c,file-handling,C,File Handling,我已经编写了一个程序来打印在linux终端上运行的“Traceroute”命令的输出。代码如下: #include <stdio.h> #include <unistd.h> #include <string.h> #include <time.h> #include "SourceIP.c" #include "RandomTraceroute.c" #include "Time.c" int main() { unsigned ch

我已经编写了一个程序来打印在linux终端上运行的“Traceroute”命令的输出。代码如下:

#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <time.h>

#include "SourceIP.c"
#include "RandomTraceroute.c"
#include "Time.c"

int main()
{
    unsigned char sourceIP[15];
    source(sourceIP);   
    printf("%s\n",sourceIP);

    unsigned char destIP[15];
    randIP(destIP); 
    printf("%s\n",destIP);

    char buff[100];
    timestamp(buff);
    printf ("%s\n", buff);

    char buf[BUFSIZ];
    snprintf(buf, sizeof(buf),"traceroute -q 1 %s >output.txt",destIP);
    system(buf);

    return 0;
}
#包括
#包括
#包括
#包括
#包括“SourceIP.c”
#包括“RandomTraceroute.c”
#包括“Time.c”
int main()
{
无符号字符源IP[15];
来源(sourceIP);
printf(“%s\n”,sourceIP);
无符号字符destp[15];
randIP(Destinp);
printf(“%s\n”,destp);
字符buff[100];
时间戳(buff);
printf(“%s\n”,浅黄色);
char buf[BUFSIZ];
snprintf(buf,sizeof(buf),“traceroute-q1%s>output.txt”,destp);
系统(buf);
返回0;
}
任务是通过删除文本文件的现有第一行,将前三行printf打印为output.txt文件的前三行。谁能给我一个答案吗。
(请考虑代码的时间复杂度)

您对下面的代码有什么看法:

#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <time.h>

#include "SourceIP.c"
#include "RandomTraceroute.c"
#include "Time.c"

int main()
{
    FILE *f = fopen("output.txt", "w");

    unsigned char sourceIP[15];
    source(sourceIP);   
    fprintf(f, "%s\n", sourceIP);

    unsigned char destIP[15];
    randIP(destIP); 
    fprintf(f, "%s\n", destIP);

    char buff[100];
    timestamp(buff);
    fprintf(f, "%s\n", buff);

    fclose(f);

    char buf[BUFSIZ];
    snprintf(buf, sizeof(buf),"traceroute -q 1 %s 2> /dev/null >> output.txt", destIP);
    system(buf);

    return 0;
}
#包括
#包括
#包括
#包括
#包括“SourceIP.c”
#包括“RandomTraceroute.c”
#包括“Time.c”
int main()
{
文件*f=fopen(“output.txt”,“w”);
无符号字符源IP[15];
来源(sourceIP);
fprintf(f,“%s\n”,源IP);
无符号字符destp[15];
randIP(Destinp);
fprintf(f,“%s\n”,destp);
字符buff[100];
时间戳(buff);
fprintf(f,“%s\n”,浅黄色);
fclose(f);
char buf[BUFSIZ];
snprintf(buf,sizeof(buf),“traceroute-q1%s2>/dev/null>>output.txt”,destIP);
系统(buf);
返回0;
}

#包括“SourceIP.c”#包括“RandomTraceroute.c”#包括“Time.c”
…嗯。。如果需要一本好的C语言书,也许你也需要一个神秘主义者。这3个C文件只是返回3个字符数组。问题是在文本文件中打印这3个值。@SouravGhosh试图说的是,几乎从不包括*.c文件。分别编译它们并链接到它们.Thanx。它起作用了。但是我不知道第一条线是怎么移动的。此代码从traceroute输出的现有第一行打印相位