본문 바로가기
chatgpt/coding with ai

[c lang] code2GPT

by SpeeDr00t 2023. 2. 7.
반응형
/*
written by jueon
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#define MAX_LENGTH 1000
#define FILENAME "toGPT.txt"
int fileInsert(char* readfile, char* inputfilename)
{
FILE * fp;
FILE * rf;
char str[MAX_LENGTH];
rf = fopen(readfile, "r");
fp = fopen(FILENAME, "w+");
if(fp == NULL || rf == NULL)
{
printf("There is a error at opening file");
return 1;
}
int i = 0;
while(fgets(str, MAX_LENGTH, rf) != NULL)
{
str[strlen(str) - 1] = '\0';
if(i++ == 0)
{
fprintf(fp,"echo \'%s\' > %s\n", str, inputfilename);
}
else
{
fprintf(fp,"echo \'%s\' >> %s\n", str, inputfilename);
}
}
fclose(fp);
fclose(rf);
return 0;
}
int main(int argc, char** argv)
{
if(argv[1] && argv[2])
{
fileInsert(argv[1], argv[2]);
}
else
{
printf("Usage : ./code2GPT [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");
}
return 0;
}
view raw code2GPT.c hosted with ❤ by GitHub

https://youtu.be/vzo6kq66_Qg

 

반응형

'chatgpt > coding with ai' 카테고리의 다른 글

[c++] code2GPT  (0) 2023.02.07
[bash shell] code2GPT  (0) 2023.02.07
[ruby] code2GPT  (0) 2023.02.07
[rust] code2GPT  (0) 2023.02.07
[python] code2GPT  (0) 2023.02.07