Friday, November 21, 2014

C command line pro



C Program to Print all Arguments passed using Command Line

 #include
#include
int main(int args, char *argv[])
 {
    int i = 0;
    for (i = 0; i < args; i++)
        printf("\n%s", argv[i]);
    return 0;
}

C program to add two numbers using command line arguments parameters

 #include
#include
 void main(int argc, char * argv[])
   {
   int i, sum = 0;

   if (argc != 3)
   {
      printf("you have forgot to type numbers.");
      exit(1);
   }
    printf("the sum is : ");
    for (i = 1; i < argc; i++)
      sum = sum + atoi(argv[i]);
    printf("%d", sum);
 }

Output

The sum is : 30

C Program to Print all Arguments passed using Command Line

 #include
#include 
int main(int args, char *argv[])
 {
    int i = 0;
    for (i = 0; i < args; i++)
        printf("\n%s", argv[i]);
    return 0;
}

C program to display mouse pointer in textmode

 #include
#include
int initmouse();
void showmouseptr();
union regs i, o;
int main()
{
   int status;
   status = initmouse();
   if (status == 0)
 {
      printf("mouse support not available.n");
   }
     else
{
      showmouseptr();
   }

   return 0;
}
 int initmouse()
{
   i.x.ax = 0;
   int86(0x33, &i, &o);
   return (o.x.ax);
}
void showmouseptr()
{
   i.x.ax = 1;
   int86(0x33, &i, &o);
}

Output

It will display Mouse Pointer

C Program to check if mouse support is available or not

#include
#include
int initmouse();
union regs i, o;
int main()
{
   int flag;
   flag = initmouse();
   if (flag == 0)
 {
      printf("mouse support not available.");
   }
    else
{
      printf("mouse support available.");
   }
   return 0;
}
int initmouse()
{
   i.x.ax = 0;
   int86(0x33, &i, &o);
   return (o.x.ax);
}

Output

Mouse support available

No comments:

Post a Comment