prowessapps.in Utility Codes

 C Program to get current date.

#include<stdio.h>
#include<dos.h>  
int main () {
 struct date d;
 getdate(&d);

 printf("Date :%d",d.da_day);
 printf("Month:%d",d.da_mon);
 printf("Year:%d",d.da_year);
 return 0;
}
OUTPUT :
Date : 3
Month: 9
Year : 2016

 C Program to get current time.

#include<stdio.h>
#include<dos.h>  
int main () {
 struct time t;
 gettime(&t);

 printf("HH : %d",t.ti_hour);
 printf("MM : %d",t.ti_min);
 printf("SS : %d",t.ti_sec);
 return 0;
}
OUTPUT :
HH : 21
MM : 42
SS : 12

 C Program to get random number.

#include<stdio.h>
#include<stdlib.h>  
int main () {
  int i, r;
  time_t t;
  /*random number generator */
  srand((unsigned) time(&t));
  /*5 random no from 0 to 49*/
  for( i = 0 ; i < 5 ; i++ ) {
      r = rand()%50;
      printf("%d\n",r);
   }
  return 0;
}
OUTPUT :
35
25
29
36
21

 C Program to get text in red.

#include<stdio.h>
#include<conio.h>

int main()
{
  textcolor(RED);
  cprintf("C Prowess!!");
  return 0;
}
OUTPUT :
C Prowess!!

 C Program to get blinking text.

#include<stdio.h>
#include<conio.h>
 
int main()
{
   textcolor(MAGENTA+BLINK);
   cprintf("C programming");
   return 0;
}
OUTPUT :
C Prowess!!

 Command Line Arguments.

#include<stdio.h>
int main(int c, char *v[])
{
 if(c!=2) {
   printf("NO-NAME!!");
 }
 else {
  printf("Hello %s!!", v[1]);
 }
  return 0;
}
OUTPUT :
ATTEMPT:1
 ~Desktop$ gcc demo.c
 ~Desktop$ ./a.out
 
  NO-NAME!!

ATTEMPT:2
 ~Desktop$ gcc demo.c
 ~Desktop$ ./a.out faiz
 
  Hello faiz!!


 Variable-argument in C.

#include<stdarg.h>
#include<stdio.h>

int sum(int, ...);

int main( )
{
 int res1, res2;
 res1 = sum(10,20);
 res2 = sum(10,20,30,40);
 printf("RESULT1: %d",res1);
 printf("RESULT2: %d",res2);
 return 0;
}

int sum(int c, ...)
{
   int val = 0;
   va_list ap;
   int i;

   va_start(ap,c);
   for(i = 0; i < c; i++) 
   {
      val += va_arg(ap, int);
   }
   va_end(ap);
 
   return val;
}
OUTPUT :
RESULT1 : 30
RESULT2 : 100

 C Program take password from user.

#include<stdio.h>
int main() {
 char pass[25], ch;
 int i,j;
 puts("Enter password : ");
 while (1) {
  if (i < 0) {
   i = 0;
  }
  ch = getch();
  if (ch == 13)
   break;
   if (ch == 8) {
    printf("\r");
    for(j=0;j< i;j++)
     printf(" ");
    i--;
    printf("\r");
    for(j=0;j< i;j++)
     printf("*");
    continue;
  }
  pass[i++] = ch;
  ch = '*';
  putch(ch);
 }
 pass[i] = '\0';
 printf("\nPassword :%s", pass);
 return 0;
}
OUTPUT :
Enter password : *******
Password :Prowess

 C Program to print this

#include<stdio.h>
#include<time.h>

int main( ) 
 {
  while(1){
   time_t  t = time(0);
   struct tm * now = localtime( &t );
   printf("\r%d:%d:%d",now->tm_hour,now->tm_min,now->tm_sec);
   sleep(1);
 }
  return 0;
}


Get it on Google Play


CONTACT DETAILS

info@prowessapps.in
(8AM to 10PM):

+91-9026070669 , +91-9451396824

© 2016, prowessapps.in, All rights reserved