i am doing a work that use srt(subtitle file)
what i support to do is
in command promt user can type:
video title -u 3000 subtitle name
after that the subtitle will appear 3 seconds after the actor speaks
this is wat i have so far:
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "Subtitle.h"
typedef char string[16];
struct subStruct{
int order;
unsigned long statHour;
unsigned long statMin;
unsigned long statSec;
unsigned long endHour;
unsigned long endMin;
unsigned long endSec;
string sub;
};
/*
* Check all values in the array
* intput : array of characters
* output : No Change
* return :
* TRUE if array contains only [a..z A..Z 0..9]
FALSE if vise versa
*/
int check_value(char * value){
int i;
int len = strlen(value);//lenght of the string
for(i = 0; i<len;i++){
if(isalnum(*(value + i))==FALSE)
return FALSE;
}
}
int check_param(char *i_option,char *i_value,char *d_option,char *d_value,char *t_option,char *t_value,char *o_option, char *o_value){
int param_num;
if(param_num >= 7){
//check option
if(strcmp(i_option,"-f") != 0) return FALSE;
if(strcmp(d_option,"-d") != 0) return FALSE;
if((strcmp(d_value,"-u") && strcmp(d_value,"-d")) != 0) return FALSE;
if(strcmp(t_option,"-t") != 0) return FALSE;
if(strcmp(o_option,"-o") != 0) return FALSE;
if(check_value(i_value)==FALSE);
if(check_value(d_value)==FALSE);
if(check_value(t_value)==FALSE);
if(check_value(o_value)==FALSE);
} else {
return FALSE;
}
return TRUE;
}
void convertStruct(char *fileName){
FILE *textFile;
struct subStruct * sub;
int count = 0;
char buff[500];
char *ptr;
textFile = fopen(fileName,"r"); /* open text file for reading */
if (textFile == NULL){
perror("File can't be found");
return;
}
sub = (struct subStruct*) malloc(sizeof(struct subStruct));
while(!feof(textFile)){
fgets(buff, 255, textFile);
(*sub).order = ptr[0]; /*subttile order */
ptr = strtok(0, ":");
(*sub).statHour = ptr[0]; /*get start hour */
ptr = strtok(0, ":");
(*sub).statMin = ptr[0]; /*get start min */
ptr = strtok(0, ":");
(*sub).statSec = ptr[0]; /*get second */
ptr = strtok(0, ":");
(*sub).endHour = ptr[0]; /*get end hour */
ptr = strtok(0, ":");
(*sub).endHour = ptr[0]; /*get end min */
ptr = strtok(0, ":");
(*sub).endHour = ptr[0]; /*get end sec */
strcpy((*sub).sub, ptr); /* subtitile */
}
fclose(textFile);
}
unsigned long convertMil(unsigned long hour,unsigned long min,unsigned long sec){
return (hour * 3600000)+(min * 60000)+(sec * 1000);
}
int main(int argc, char** argv) {
convertStruct("video.srt");
return (EXIT_SUCCESS);
}
now my problem is:
i got segmentation false in converStrust()
wat convertStruct does is to read and store struct of srt into .srt file
Can anyone help me?
sample structure of .srt is:
1
00:00:45,000 --> 00:00:50,400
Hello
2
00:00:50,300 --> 00:00:58,200
Goodbye
or any1 have different way to solve my problem.Please tell me.
thanks for ur time