【问题标题】:can you help me in this (C lang)? [closed]你能帮我解决这个问题吗(C 语言)? [关闭]
【发布时间】:2014-03-20 12:56:42
【问题描述】:

编写一个带有两个命令行参数的程序。第一个是字符串;第二个是 文件的名称。然后程序应该搜索文件,打印包含字符串的所有行。 因为这个任务是面向行而不是面向字符的,所以使用 fgets() 而不是 getc()。采用 标准 C 库函数 strstr() 在每一行中搜索字符串。假设没有更长的行 超过 255 个字符。

【问题讨论】:

  • 您忘记包含到目前为止为此练习编写的代码。
  • 是的,我们可以,虽然你忘了问你真正的问题。
  • 我做家庭作业每小时收费 300 美元...
  • 这里没人做作业
  • 我认为你在错误的堆栈站点...codegolf.stackexchange.com

标签: c


【解决方案1】:
/* with thanks to @AduaitPokhriyal */
#include <stdio.h>

int main(int argc, char *argv[])
{
    char command[100]; /* i hope this is large enough! */
    sprintf(command, "grep %s %s", argv[1], argv[2]); /* i hope the arguments are there and valid! */
    system(command); /* surely "grep" must use strstr() somewhere */
    return 0;
}

【讨论】:

    猜你喜欢
    • 2011-01-24
    • 2021-08-14
    • 2022-06-15
    • 1970-01-01
    • 2021-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-29
    相关资源
    最近更新 更多