This is an old revision of the document!


Program za podesavanje titlova

Kao argument se zadaje ime fajla i ime novog fajla(opciono), zatim se unose sati, minuti, sekunde i milisekunde za koliko da se izvrsi pomeranje. Program kreira novi fajl sa promenjenim vrednostima.

subtitle.c
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
 
void izlaz(char *s,char *u){
	int i=0;
	while(u[i]!='\0' && u[i]!='.') s[i]=u[i++];
	s[i]='1';
	while(u[i]!='\0') s[i+1]=u[i++];
	s[i+1]='\0';
	printf("\nIzlazni fajl: %s\n",s);
}
 
void move(FILE *g,char line[],int h1,int m1,int s1,int ms1){
	int i,j,prenos=0,h,m,s,ms;
	char num[3],mil[4];
 
	mil[3]=num[2]='\0';//milisekunde i broj(za h i m) stavljamo kraj stringa
	for(i=0;i<2;i++){
		//milisekunde
		mil[0]=line[9+i*17];
		mil[1]=line[10+i*17];
		mil[2]=line[11+i*17];
 
		ms=atoi(mil)+1000+ms1;//1000 pozajmljujemo 1s od sekundi
		prenos=ms/1000;
		ms=ms%1000;
 
		//sekunde
		num[0]=line[6+i*17];
		num[1]=line[7+i*17];
 
		s=s1+atoi(num)+prenos-1+60; //-1 -> zbog onog one koje smo pozajmili u ms, 60 -> pozajmljujemo 1min
		prenos=s/60;
		s=s%60;
 
		//minuti
		num[0]=line[3+i*17];
		num[1]=line[4+i*17];
 
		m=m1+atoi(num)+prenos-1+60;//-1 zbog onog one koje smo pozajmili u s, 60->pozajmljujemo 1sat
		prenos=m/60;
		m=m%60;
 
		//sati
		num[0]=line[0+i*17];
		num[1]=line[1+i*17];
		h=h1+atoi(num)+prenos-1; //-1 zbog onog one koje smo pozajmili u m
		//stampa
		if(h<10) fprintf(g,"0");
		fprintf(g,"%d:",h);
		if(m<10) fprintf(g,"0");
		fprintf(g,"%d:",m);
		if(s<10) fprintf(g,"0");
		fprintf(g,"%d,",s);
		if(ms<100) fprintf(g,"0");
		if(ms<10) fprintf(g,"0");
		if(i==0) fprintf(g,"%d --> ",ms);
		else fprintf(g,"%d\n",ms);
	}
}
main(int argc,char *argv[]){
	FILE *f,*g;
	char *new,line[40];
	int h=0,m=0,s=0,ms=0,i=0;
	if(argc<2 || argc>3){
		printf("Upotreba: %s ULAZNI_FAJL [IZLAZNI_FAJL]\n",argv[0]);
		exit(0);
	}
	f=fopen(argv[1],"r");
	if(!f){
		printf("Fajl ne postoji\n");
		exit(0);
	}
	if(argc==3){
		g=fopen(argv[2],"w");
	}
	else{
		new=(char*)malloc(sizeof(argv[1])+1);
		izlaz(new,argv[1]);
		g=fopen(new,"w");
		free(new);
	}
	printf("hh mm ss ms?\n");
	scanf("%d%d%d%d",&h,&m,&s,&ms);
	while(1){
		fgets(line,40,f);
		if(feof(f)) break;
		if(line[2]==':' && line[5]==':'){
			move(g,line,h,m,s,ms);
			i++;
		}
		else fprintf(g,"%s",line);
	}
	fclose(f);
	fclose(g);
	printf("\n%d reda izmenjeno\n\n",i);
}

<=Nazad

 
titlovi.1330542529.txt.gz · Last modified: 2012/02/29 20:08 by tomislav.mrda
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki