写一段python程序,把一个UTF-8编码的文本文件转成C语言数组
时间: 2023-11-27 10:53:32 浏览: 71
以下是一个将UTF-8编码的文本文件转换为C语言数组的Python程序:
```python
with open("input.txt", "r", encoding="utf-8") as file:
content = file.read()
output = "{"
for char in content:
output += str(ord(char)) + ", "
output = output[:-2] + "};"
with open("output.txt", "w") as file:
file.write(output)
```
该程序将读取名为"input.txt"的UTF-8编码文本文件,将其内容转换为C语言数组,并将结果写入名为"output.txt"的文件中。
阅读全文