Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 在许多文件中用/替换\的脚本是什么样子的?_C_Windows_Posix_Include Path - Fatal编程技术网

C 在许多文件中用/替换\的脚本是什么样子的?

C 在许多文件中用/替换\的脚本是什么样子的?,c,windows,posix,include-path,C,Windows,Posix,Include Path,是的,这是一个非常懒惰的问题,但我认为这是一个人们经常遇到的问题,这里的人可能已经写了一些东西来分享 我有大量的C文件,其中包含使用Windows相对路径的#include语句。我正在其他操作系统(马上,在我的OSX开发机器上)上编译代码,需要在这些include语句中用正斜杠替换所有反斜杠。因此,从像#包含“libs\helper.h”到#包含“libs/helper.h” 这应该非常健壮,因为它可以捕获任何合法格式的#include,但不能捕获任何其他格式。您应该在OSX中使用bash/aw

是的,这是一个非常懒惰的问题,但我认为这是一个人们经常遇到的问题,这里的人可能已经写了一些东西来分享

我有大量的C文件,其中包含使用Windows相对路径的
#include
语句。我正在其他操作系统(马上,在我的OSX开发机器上)上编译代码,需要在这些include语句中用正斜杠替换所有反斜杠。因此,从像
#包含“libs\helper.h”
#包含“libs/helper.h”


这应该非常健壮,因为它可以捕获任何合法格式的
#include
,但不能捕获任何其他格式。

您应该在OSX中使用bash/awk/sed

for cfile in *.c
do
  awk '/#include/{gsub(/\\/,"/")}1' cfile >temp
  mv temp cfile
done


Sed是前进的方向,所以请在mac上进行


sed'/^\include/s/\/\///g'

看起来像是一个5字符正则表达式的作业。假设您在其他地方不使用反斜杠。
for cfile in *.c
do
  awk '/#include/{gsub(/\\/,"/")}1' cfile >temp
  mv temp cfile
done
 sed -i.bak '/#include/s/\\/\//g' *.c