Social Icons

Friday, 3 May 2013

Time Using Ctime Function


#include<unistd.h>
#include<time.h>
#include<stdio.h>
int main()
{
time_t t1,t2;
struct tm *tm_ptr;
int m,p,u;
char *n;
time(&t1);

n=ctime(&t1);


printf("\n time is %s",n);
return 0;
}



Time Using Localtime Function


#include<unistd.h>
#include<time.h>
#include<stdio.h>
int main()
{
time_t t1,t2;
struct tm *tm_ptr;
int m,p,u;
char *n;
time(&t1);

tm_ptr=localtime(&t1);


printf("\n year %2d  : mon %2d    hour  %2d, Minute %2d , Second %2d",tm_ptr->tm_year+1900,tm_ptr->tm_mon+1,tm_ptr->tm_hour,tm_ptr->tm_min,tm_$
return 0;
}

Time Function Using C program


#include<unistd.h>
#include<time.h>
#include<stdio.h>
int main()
{
time_t t1,t2;
int m,p,u;
char *n;
time(&t1);

m=t1;
printf("\n time is %d",m);

printf("\n enter your name :");
scanf("%s",n);

time(&t2);

p=t2;
printf("\n time is %d",p);

u=p-m;
printf("\n time taken in writing name is : %d",u);


return 0;
}

Thursday, 2 May 2013

Thread cancelletion Using Deferred Cancel Type


#include<unistd.h>
#include<stdio.h>
#include<stdlib.h>
#include<pthread.h>
#include<string.h>
void  *func1(void *arg);
char m[]="hi how r u";

int main()
{
int r,x;
void *p;
pthread_t a;
r=pthread_create(&a,NULL,func1,(void *)m);
if(r!=0)
{

perror("thread creation failed : ");
exit(EXIT_FAILURE);
}
else
sleep(3);
x=pthread_cancel(a);
if(x==-1)
{
perror("thrAed cancel failed ");


}

else
sleep(3);
x=pthread_cancel(a);
if(x==-1)
{
perror("thrAed cancel failed ");


}
else
{
printf("\n thread cancelled");

r=pthread_join(a,&p);
if(r!=0)
{
perror("thread joining failed :");
exit(EXIT_FAILURE);
}
printf("\n thread joined with value %s ", (char *)p);
printf("\n messafe is %s",m);
exit(EXIT_SUCCESS);
}
}



 

Sample Text

Sample text

 
Just Programming Cse DriveReputation Management