gpt4 book ai didi

c - 使用shell脚本打印c文件中的函数名称?

转载 作者:行者123 更新时间:2023-11-30 21:06:18 25 4
gpt4 key购买 nike

例如,如果我有 C 文件:

game.c
int main(){
//code
}

hello.c
int something(){
//code
}

我如何获得输出:

/directory/path/game.c
int main()

/directory/path/hello.c
int something()

我已经编写了一个 for 循环来迭代目录中以 .c 结尾的文件,但不确定如何输出函数名称?

所以我尝试执行一个 shell 脚本,该脚本将读取 C 文件,然后输出其函数名称。

for file in $(find $1 -type f -name '*.c')
do
echo $file
grep -r "what to search for??"

done

最佳答案

您可以使用正则表达式从文件中提取函数声明。您可以在这里查看:Regex to pull out C function prototype declarations?

如果该行与正则表达式匹配,则可以打印它。

关于c - 使用shell脚本打印c文件中的函数名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49570019/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com