Pages - Menu

Showing posts with label C Cool Codes. Show all posts
Showing posts with label C Cool Codes. Show all posts

Saturday, 19 July 2014

Shutdown system using C.

You can shutdown your system using a c program.
Here is the code to shut down the system in c.

For window xp:

(After 30 seconds)

 If you are using turbo c then you can not do that from the compiler directly you should execute the file from folder.
#include <stdio.h>
#include <stdlib.h>

int main()
{
   char c;

   printf("Do you want to shutdown your system: (y/n)\n");
   scanf("%c",&c);

   if (ch == 'y' || ch == 'Y')
      system("C:\\WINDOWS\\System32\\shutdown -s");
   return 0;
}

Program without main in C.

Here is a simple C PROGRAM without using a main() function.



#include<stdio.h>
#define Compose(f,a,b,c,d,e) c##d##a##b
#define start Compose(f,i,n,m,a,f)
int start()
{
    printf("Hello.");
    return 1;
}

Concept:


## Concatenates two characters when we define start as decode(f,i,n,m,a,f) then it is decoded as main.
So there is a hidden main here.

Another program is



Printing Map of India in C.

Concept:

The long string is simply a binary sequence converted to ASCII. The first for statement makes start out at 10, and the [b+++21] after the string yields 31. Treating the string as an array, offset 31 is the start of the "real" data in the string (the second line in the code sample you provided). The rest of the code simply loops through the bit sequence, converting the 1's and 0's to !'s and whitespace and printing one character at a time.


HERE is the code for the map:

#include <stdio.h>
int main()
{
    int a,b,c;
    int count = 1;
    for (b=c=10;a="- FIGURE?, UMKC,XYZHello Folks,\
    TFy!QJu ROo TNn(ROo)SLq SLq ULo+\
    UHs UJq TNn*RPn/QPbEWS_JSWQAIJO^\
    NBELPeHBFHT}TnALVlBLOFAkHFOuFETp\
    HCStHAUFAgcEAelclcn^r^r\\tZvYxXy\
    T|S~Pn SPm SOn TNn ULo0ULo#ULo-W\
    Hq!WFs XDt!" [b+++21]; )
    for(; a-- > 64 ; )
    putchar ( ++c=='Z' ? c = c/ 9:33^b&1);
    return 1;
}

Quine in c

A program that prints itself is called Quine program

Concept:


Open the same file in read mode and start reading and printing from the file character by character till END OF FILE is reached Here is the code:

#include<stdio.h>
int main()
{
FILE *fp;
char ch;
fp=fopen("selfprint.c","r");
/* Enter your program name here*/
while((ch=fgetc(fp))!=EOF)    
printf("%c",ch);
fclose(fp);    
return(1);
}

Another code is here