Some very interesting programming code snippets.

This perl script is an old piece of code that will create a Windows version text string. I am sure someone might find this useful. #!/usr/bin/perl   use warnings;   @t = localtime(time());   $yr = ($t[5] + 1900) -1; $sr = int(( $t [4]/4) + 1); $v = int("$t[7]$t[2]$t[1]$t[0]"*((rand(rand(10)…

Read More

Funny and strange UNIX happenings and C programming tips.

Funny and cool Linux tips 1337 or Leet in the UNIX time. -01:44:57– gordon@deusexmachina [~]$ date +%s 1337096699-01:44:57– gordon@deusexmachina [~]$ date +%s 1337096699 The missing days in 1752. I have mentioned this before, but it is worth mentioning again. -01:45:31– gordon@deusexmachina [~]$ cal 9 1752 September 1752 Su Mo Tu…

Read More

Count the actual lines of code in your C or C++ project.

This is how to actually count the lines of code in your C project on Linux. Some people advocate using wc -l, but that would not suit our purposes. The cloc utility is able to do this and more. Firstly, install this utility. sudo apt install clocsudo apt install cloc…

Read More

C program to write a string to a file.

I think I may have posted this before, but this is a little program I am working on that writes a text string to a file. I have got it to work perfectly and it compiles without errors using gcc -Wall. /* * This program is free software; you can…

Read More

A simple random number routine in C.

This is a simple random number example in C. This will print a random number from 1 – 64. #include <stdio.h> #include <stdlib.h>   int main (void) {   srand(time(NULL)); int r = rand() % 64;   printf("Random INT: %i\n", r);   return 0; }#include <stdio.h> #include <stdlib.h> int main…

Read More

Useful C tricks and code samples.

How to define a string and print it out with the printf() function. #include <stdio.h>   /* Defining a global string. */   #define hi "Hello Sire."   int main(void) { /* Printing out the string. */ printf("%s\n", hi);   return 0; }#include <stdio.h> /* Defining a global string. */…

Read More

How to include code inside a loop in C.

This loop I wrote in C enables if statements inside a loop. This could be a useful thing to know. #include <stdio.h>   int main(void) { int k;   for (k = 0; k < 16; k++) { printf("* *\n"); if (k == 4 || k == 12) { printf("\n\t\t-\n");…

Read More

The simplest hello world program you can write in C.

This is a very simple Hello World program that you can write in C. int main (void) {   write (1, "Hello World\n", 14); return 0; }int main (void) { write (1, "Hello World\n", 14); return 0; } Just compile the program like this: localhost% cc minimal.c -o small minimal.c:…

Read More

Very cool code that prints a tick sign in asterisks. This is awesome C++ code.

This code prints out a tick sign using asterisks. I tested this code on Fedora 19 and gcc 4.8 and it compiles without any problems. #include <iostream> #include <iomanip>   using std::cout;   int main() {   cout<<std::setw(8)<<"*"<<"n"; cout<<std::setw(7)<<"*"<<"n"; cout<<std::setw(6)<<"*"<<"n";   cout<<"* *"<<"n"<<"* *"<<"n"<<"*"; cout<< "n";   return 0; }#include…

Read More

Some very good Linux resources for learning programming and BASH scripting.

http://gentoomen.org/tutorials/resources.html. The gentoomen.org resources page. Very good list of links to various tutorials and help pages. http://tldp.org/LDP/abs/html/. The Advanced BASH scripting guide. ftp://ftp.vim.org/pub/vim/doc/book/vimbook-OPL.pdf. The VIM guideboook. http://stommel.tamu.edu/~baum/programming.html. 3000 useful guides to programming and Linux documentation and help pages. http://samizdat.mines.edu/howto/HowToBeAProgrammer.html. How to be a programmer. A short but comprehensive summary. http://www.psychocats.net/ubuntu/index….

Read More

Cool C programs and some very useful code snippets to make programming even more fun.

A very obfuscated C program. typedef unsigned char t;t*F="%c",l[]="|\\/=_ \n](.\0(),*(.(=(}*.)[[*.",N=’\n’,* r;typedef(*H)();extern H Ar;Q(a){return(a|-a)>>31;}H S(c,a){return(H)(a&~c|(int )Ar&c);}extern t*ist;V(t*u){*u^=*u&2^(*u>>7)*185;}Z(t*u,t n){*u-=n;}e(t c,H h){ R(h,Q(* r^c));} I(){r=l +7-4*Q( getchar ()^*l); }R(H h, int c){Ar=S (c,h);- main() ;}P(){r ++;}z() { O(&N);} O(t*c){ printf( F,+*c); }T(){r= "This is not a function\n" ;}w(U){ U=Z(r,8 ); r-=~Q(* r/8-4); return…

Read More

Running a command within another program. How to do this with C.

This code snippet will run the date command. The execl() function is very useful for executing a command within your C program.You replace the NULL identifiers with any extra arguments to pass to the program. I prefer this over the system() function. #include <unistd.h>   int main(void) {   execl("/bin/date",…

Read More