Tema: Re: Reikia helpo su C stringais
Autorius: Autėjus
Data: 2010-11-04 11:43:46
>> "Tomis"
>> Padekit zaliam. 

Pabandziau supaprastinta - viskas veikia. Klaida kazkur uz teksto ribu..
Stai kodas:


#include <stdio.h>  /* butina, apraso ivedima/isvedima */
#include <string.h> /* butina dirbant su stringais */

char
*Time2Txt(long TimeS){
long time;
short days, hours, minutes, seconds;
char a[150];
char d[9];
char h[9];
char m[9];
char s[9];
unsigned char Q;
time=TimeS;
 printf("Time2Txt TimeS: %u\r\n",TimeS);
 printf("Time2Txt time: %u\r\n",time);
days=time/86400;
time=time-(days*86400);
hours=time/3600;
time=time-(hours*3600);
minutes=time/60;
seconds=time-(minutes*60);
sprintf(d, "%02dd ",days);
sprintf(h, "%02dh ",hours);
sprintf(m, "%02dm ",minutes);
sprintf(s, "%02ds",seconds);
       printf("Time2Txt formated: %s%s%s%s \r\n",d,h,m,s);
strcpy(a,"");
if (days>0) strcat(a,d);
if (hours>0) strcat(a,h);
if (minutes>0) strcat(a,m);
if (seconds>0) strcat(a,s);
if (TimeS==0) strcpy(a,"0?");
       printf("Time2Txt result: %s \r\n",a);
return a;
}


main(void){
#define Status "F022.Status"
#define Act "F022.TimeAct"
#define Def "F022.TimeDef"
char txt[100]="";
char d[100]="";
char a[100]="";
//TSandFilter F;
 printf("#########_main started\r\n");
//F.raw=GetTagDWord(Status);
strcpy(d,Time2Txt(125));
strcpy(a,Time2Txt(248));
       printf("_main: result a:%s\r\n",a);
       printf("_main: result d:%s\r\n",d);
sprintf(txt,"Stadija: %s\r\nUzduota: %s\r\nPraejo: %s","uuu",d,a);
 printf("_main: result txt:%s\r\n",txt);
 printf("##########_main end\r\n");
}