동영상의 자막파일이 있는데, 너무 한 화면에 나오는 자막의 길이가 길 때 다음 프로그램을 사용하여 수정이 가능하다.
자세한 사용법은 추후에 올리도록 할 예정이고, 우선 Code만 소개한다.
다음의 코드를 fix_youtube_srt.c에 저장한다.
#include <stdio.h> //
#include <stdlib.h> // malloc
#include <string.h>
typedef struct Node {
char word[128];
struct Node *next;
} Node;
Node *push(Node *head, char *myword) {
Node *stone=(Node *) malloc(sizeof(Node));
strcpy(stone->word, myword);
stone->next=head;
head = stone;
return head;
}
int print(Node *head) { Node *p;
strcpy(head->word, "1"); /* just because you have strange char on the first data */
for(p = head; p != NULL; p = p->next) {
printf("%s\n", p->word);
}
return 0;
}
Node *clear(Node *head) { Node *p, *tmp;
for(p=head;p!=NULL;p=tmp) {
tmp=p->next;
free(p);
}
return (head = NULL);
}
Node *reverse(Node *head) { Node *p, *head2=NULL;
Node *tmp, *stone;
for(p=head; p!=NULL; p=tmp) {
tmp =p->next;
stone=p;
stone->next=head2;
head2=stone;
}
return head2;
}
Node *go_back_4(Node* head) {
Node* p = head; /* Initialize current */
int cnt1 = 0;
while (p != NULL) {
p = p->next;
if(++cnt1 == 4 ) return p;
}
return NULL;
}
int main( ) { Node *head = NULL; Node *p; Node *t; char *ptr;
char buf[256];
char cpy[256];
while( fgets(buf, sizeof(buf)-1, stdin) != NULL ) {
buf[strcspn(buf, "\n")]=0; /* remove new line char */
head = push(head, buf);
}
for(p = head; p != NULL; p = p->next) {
strcpy(cpy, p->word);
if((ptr=strstr(cpy, " -->"))) {
*ptr=0; /* get 1st part before --> */
t = go_back_4(p); /* go back 4 nodes */
if( t == NULL ) break;
if( (ptr=strstr(t->word, " --> ")) ) {
ptr += 5; *ptr = 0; /* cut 2nd part */
strcat(t->word, cpy);
}
}
}
head = reverse(head);
print(head);
return 0;
}
'C 언어' 카테고리의 다른 글
| C언어 프로그램을 HTML 형식으로 만들기 (1) | 2021.01.03 |
|---|---|
| Json 파일을 자막 파일인 srt로 변경 (0) | 2021.01.02 |
| C언어를 이용해서 Log 함수 계산하기 (0) | 2021.01.01 |
| 매크로함수를 활용한 프로그램 (0) | 2020.12.31 |
| 자료구조 연결 리스트 함수들 정리 (0) | 2020.12.31 |
댓글