반응형
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::fs::File; | |
use std::io::{BufReader, BufRead, Write}; | |
const FILENAME: &str = "to_gpt.txt"; | |
fn file_insert(readfile: &str, inputfilename: &str) -> std::io::Result<()> { | |
let read_file = File::open(readfile)?; | |
let buf_reader = BufReader::new(read_file); | |
let mut fp = File::create(FILENAME)?; | |
for (i, line_res) in buf_reader.lines().enumerate() { | |
let line = line_res?; | |
if i == 0 { | |
fp.write_all(format!("echo '{}' > {}\n", line.trim(), inputfilename).as_bytes())?; | |
} else { | |
fp.write_all(format!("echo '{}' >> {}\n", line.trim(), inputfilename).as_bytes())?; | |
} | |
} | |
Ok(()) | |
} | |
fn main() { | |
use std::env; | |
let args: Vec<String> = env::args().collect(); | |
if args.len() == 3 { | |
match file_insert(&args[1], &args[2]) { | |
Ok(()) => {}, | |
Err(e) => println!("Error: {}", e), | |
} | |
} else { | |
println!("Usage : cargo run [Read file] [GPT file]\n'Read file' is a name of file to be read.\n'GPT file' is a name of file to be stored to ChatGPT.\n"); | |
} | |
} |
반응형
'chatgpt > coding with ai' 카테고리의 다른 글
[c++] code2GPT (0) | 2023.02.07 |
---|---|
[bash shell] code2GPT (0) | 2023.02.07 |
[ruby] code2GPT (0) | 2023.02.07 |
[python] code2GPT (0) | 2023.02.07 |
[c lang] code2GPT (0) | 2023.02.07 |