Useful Perl and C code samples.

Useful Perl And C Code.

A simple program that will read in a name and print it.

#include <stdio.h>
#include <string.h>

#define MSG "World"

int goku(void) {
	printf("Hello %s.\n", MSG);
	return 1;

int main(int argc, char **argv) {

	char *name;

	name = argv[1];

	if (strlen(name) < 5) {
		printf("Name too short.\n");
	return 0;

Another way to print the current time.

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

int makron(void) {
    	     time_t now;
    	     char* mytime;

    	     now = time(NULL);
    	     mytime = ctime(&now);
    	     printf("%s", mytime);

int main(int argc,char *argv[])

Are you wondering how to solve the FizzBuzz problem in C? This is a version of the FizzBuzz program I wrote in C. This will be useful for reference on how to do it properly.
There are many ways to code this, but this works just fine.

#include <stdio.h>

int main (void) {
	int i;
	for (i = 0; i < 101; i++) {
		if (i % 3 == 0 && i % 5 == 0) {
		else {
			if (i % 3 == 0) {
		else {
			if (i % 5 == 0) {
		printf("%d\n", i);
	return 0;

Here is a program I wrote to set a random wallpaper for a GNU/Linux
desktop. Just type wmsetbg -s ~/Wallpapers/photohm/$(img) to set a
random wallpaper. Compile with gcc -Wall -Os photos.c -o img. Very nice

* Description: Random image program.
* Author: bejiitas
* Created at: Tue Apr 17 02:08:47 EDT 2007
* Computer: opensuse
* System: Linux on i686
* Copyright (c) 2007 bejiitas_wrath  All rights reserved.
 * This is how I generated this list in the first place...
 * for file in *.jpg; do echo -ne "\"$file\"," >> ~/out.txt; done;
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
const char* files[] = {
	"j0144216.jpg", "j0144217.jpg", "j0144226.jpg", "j0144227.jpg",
	"j0144228.jpg", "j0144232.jpg", "j0144233.jpg", "j0144234.jpg",
	"j0144235.jpg", "j0144236.jpg", "j0144237.jpg", "j0144243.jpg",
	"j0144247.jpg", "j0144248.jpg", "j0144269.jpg", "j0144281.jpg",
	"j0144282.jpg", "j0144287.jpg", "j0144288.jpg", "j0144291.jpg",
	"j0144294.jpg", "j0144295.jpg", "j0144296.jpg", "j0144297.jpg",
	"j0144300.jpg", "j0144301.jpg", "j0144302.jpg", "j0144304.jpg",
	"j0144305.jpg", "j0144306.jpg", "j0144308.jpg", "j0144309.jpg",
	"j0144310.jpg", "j0144311.jpg", "j0144312.jpg", "j0144314.jpg",
	"j0144318.jpg", "j0144324.jpg", "j0144325.jpg", "j0144326.jpg",
	"j0144329.jpg", "j0144333.jpg", "j0144337.jpg", "j0144338.jpg",
	"j0144340.jpg", "j0144343.jpg", "j0144344.jpg", "j0144345.jpg",
	"j0144346.jpg", "j0144347.jpg", "j0144348.jpg", "j0144349.jpg",
	"j0144351.jpg", "j0144352.jpg", "j0144353.jpg", "j0144354.jpg",
	"j0144355.jpg", "j0144356.jpg", "j0144357.jpg", "j0144358.jpg",
	"j0144359.jpg", "j0144360.jpg", "j0144361.jpg", "j0144362.jpg",
	"j0144365.jpg", "j0144367.jpg", "j0144370.jpg", "j0144371.jpg",
	"j0144372.jpg", "j0144373.jpg", "j0144374.jpg", "j0144377.jpg",
	"j0144378.jpg", "j0144379.jpg", "j0144380.jpg", "j0144381.jpg",
	"j0144382.jpg", "j0144383.jpg", "j0144384.jpg", "j0144385.jpg",
	"j0144386.jpg", "j0144387.jpg", "j0144389.jpg", "j0144390.jpg",
	"j0144391.jpg", "j0144392.jpg", "j0144393.jpg", "j0144394.jpg",
	"j0144395.jpg", "j0144396.jpg", "j0144397.jpg", "j0144398.jpg",
	"j0144399.jpg", "j0144400.jpg", "j0144401.jpg", "j0144402.jpg",
	"j0144403.jpg", "j0144406.jpg", "j0144411.jpg", "j0144412.jpg",
	"j0144414.jpg", "j0144415.jpg", "j0144416.jpg", "j0144418.jpg",
	"j0144420.jpg", "j0144422.jpg", "j0144423.jpg", "j0144425.jpg",
	"j0144430.jpg", "j0144433.jpg", "j0144434.jpg", "j0144435.jpg",
	"j0144436.jpg", "j0144437.jpg", "j0144438.jpg", "j0144440.jpg",
	"j0144442.jpg", "j0144443.jpg", "j0144445.jpg", "j0144453.jpg",
	"j0144454.jpg", "j0144455.jpg", "j0144456.jpg", "j0144459.jpg",
	"j0144460.jpg", "j0144463.jpg", "j0144464.jpg", "j0144465.jpg",
	"j0144466.jpg", "j0144467.jpg", "j0144474.jpg", "j0144475.jpg",
	"j0144477.jpg", "j0144480.jpg", "j0144482.jpg", "j0144483.jpg",
	"j0144484.jpg", "j0144485.jpg", "j0144487.jpg", "j0144488.jpg",
	"j0144489.jpg", "j0144490.jpg", "j0144491.jpg", "j0144494.jpg",
	"j0144495.jpg", "j0144498.jpg", "j0144503.jpg", "j0144504.jpg",
	"j0144505.jpg", "j0144506.jpg", "j0144508.jpg", "j0144512.jpg",
	"j0144518.jpg", "j0144519.jpg", "j0144522.jpg", "j0144523.jpg",
	"j0144526.jpg", "j0144527.jpg", "j0144532.jpg", "j0144533.jpg",
	"j0144534.jpg", "j0144535.jpg", "j0144536.jpg", "j0144538.jpg",
	"j0144539.jpg", "j0144540.jpg", "j0144541.jpg", "j0144542.jpg",
	"j0144543.jpg", "j0144544.jpg", "j0144545.jpg", "j0144546.jpg",
	"j0144547.jpg", "j0144548.jpg", "j0144550.jpg", "j0144551.jpg",
	"j0144552.jpg", "j0144555.jpg", "j0144557.jpg", "j0144558.jpg",
	"j0144559.jpg", "j0144561.jpg", "j0144562.jpg", "j0144570.jpg",
	"j0144579.jpg", "j0144580.jpg", "j0144582.jpg", "j0144585.jpg",
	"j0144589.jpg", "j0144592.jpg", "j0144601.jpg", "j0144602.jpg",
	"j0144604.jpg", "j0144605.jpg", "j0144611.jpg", "j0144612.jpg",
	"j0144613.jpg", "j0144615.jpg", "j0144616.jpg", "j0144617.jpg",
	"j0144621.jpg", "j0144623.jpg", "j0144630.jpg", "j0144631.jpg",
	"j0144635.jpg", "j0144637.jpg", "j0144638.jpg", "j0144639.jpg",
	"j0144640.jpg", "j0144643.jpg", "j0144653.jpg", "j0144654.jpg",
	"j0144656.jpg", "j0144659.jpg", "j0144660.jpg", "j0144664.jpg",
	"j0144665.jpg", "j0144667.jpg", "j0144674.jpg", "j0144677.jpg",
	"j0144683.jpg", "j0144685.jpg", "j0144687.jpg", "j0144689.jpg",
	"j0144691.jpg", "j0144692.jpg", "j0144694.jpg", "j0144695.jpg",
	"j0144707.jpg", "j0144708.jpg", "j0144711.jpg", "j0144714.jpg",
	"j0144716.jpg", "j0144718.jpg", "j0144719.jpg", "j0144720.jpg",
	"j0144723.jpg", "j0144725.jpg", "j0144726.jpg", "j0144728.jpg",
	"j0144729.jpg", "j0144731.jpg", "j0144736.jpg", "j0144737.jpg",
	"j0144739.jpg", "j0144741.jpg", "j0144742.jpg", "j0144743.jpg",
	"j0144744.jpg", "j0144745.jpg", "j0144746.jpg", "j0144747.jpg",
	"j0144748.jpg", "j0144750.jpg", "j0144751.jpg", "j0144752.jpg",
	"j0144755.jpg", "j0144756.jpg", "j0144758.jpg", "j0144760.jpg",
	"j0144761.jpg", "j0144764.jpg", "j0144765.jpg", "j0144766.jpg",
	"j0144768.jpg", "j0144770.jpg", "j0144773.jpg", "j0144788.jpg",
	"j0144789.jpg",	"j0144790.jpg", "j0144791.jpg", "j0144804.jpg",
	"j0144806.jpg", "j0144807.jpg", "j0144809.jpg", "j0144810.jpg",
	"j0144817.jpg", "j0144820.jpg", "j0144821.jpg", "j0144825.jpg",
	"j0144826.jpg", "j0144829.jpg", "j0144830.jpg", "j0144831.jpg",
	"j0144843.jpg", "j0144846.jpg", "j0144847.jpg", "j0144850.jpg",
	"j0144851.jpg", "j0144852.jpg", "j0144853.jpg", "j0144854.jpg",
	"j0144857.jpg", "j0144864.jpg", "j0144865.jpg", "j0144870.jpg",
	"j0144873.jpg", "j0144874.jpg", "j0144876.jpg", "j0144877.jpg",
	"j0144878.jpg", "j0144879.jpg", "j0144884.jpg", "j0144890.jpg",
	"j0144891.jpg", "j0144892.jpg", "j0144893.jpg", "j0144894.jpg",
	"j0144895.jpg", "j0144896.jpg", "j0144897.jpg", "j0144898.jpg",
	"j0144899.jpg", "j0144901.jpg", "j0144902.jpg", "j0144904.jpg",
	"j0144905.jpg", "j0144906.jpg", "j0144911.jpg", "j0144912.jpg",
	"j0144913.jpg", "j0144914.jpg", "j0144915.jpg", "j0144916.jpg",
	"j0144917.jpg", "j0144918.jpg", "j0144919.jpg", "j0144920.jpg",
	"j0144921.jpg", "j0144956.jpg", "j0144958.jpg", "j0144960.jpg",
	"j0144961.jpg", "j0144963.jpg", "j0144966.jpg", "j0144968.jpg",
	"j0144969.jpg", "j0144970.jpg", "j0144971.jpg", "j0144972.jpg",
	"j0144973.jpg", "j0144974.jpg", "j0144975.jpg", "j0144976.jpg",
	"j0144978.jpg", "j0144979.jpg", "j0144980.jpg", "j0144981.jpg",
	"j0144982.jpg", "j0144983.jpg", "j0144984.jpg", "j0145003.jpg",
	"j0145010.jpg", "j0145016.jpg", "j0145020.jpg", "j0145025.jpg",
	"j0145032.jpg", "j0145033.jpg", "j0145034.jpg", "j0145035.jpg",
	"j0145037.jpg", "j0145042.jpg", "j0145043.jpg", "j0145044.jpg",
	"j0145045.jpg", "j0145046.jpg", "j0145047.jpg", "j0145048.jpg",
	"j0145049.jpg", "j0145050.jpg", "j0145051.jpg", "j0145053.jpg",
	"j0145054.jpg", "j0145055.jpg", "j0145057.jpg", "j0145058.jpg",
	"j0145060.jpg", "j0145062.jpg", "j0145063.jpg", "j0145067.jpg",
	"j0145068.jpg", "j0145069.jpg", "j0145070.jpg", "j0145071.jpg",
	"j0145078.jpg", "j0145083.jpg", "j0145085.jpg", "j0145087.jpg",
	"j0145088.jpg", "j0145091.jpg", "j0145092.jpg", "j0145093.jpg",
	"j0145104.jpg", "j0145105.jpg", "j0145106.jpg", "j0145107.jpg",
	"j0145108.jpg", "j0145109.jpg", "j0145110.jpg", "j0145111.jpg",
	"j0145113.jpg", "j0145114.jpg", "j0145115.jpg", "j0145116.jpg",
	"j0145118.jpg", "j0145120.jpg", "j0145121.jpg", "j0145123.jpg",
	"j0145124.jpg", "j0145126.jpg", "j0145127.jpg", "j0145129.jpg",
	"j0145130.jpg", "j0145131.jpg", "j0145132.jpg", "j0145150.jpg",
	"j0145151.jpg", "j0145152.jpg", "j0145153.jpg", "j0145162.jpg",
	"j0145164.jpg", "j0145174.jpg", "j0145175.jpg", "j0145176.jpg",
	"j0145181.jpg", "j0145186.jpg", "j0145187.jpg", "j0145188.jpg",
	"j0145190.jpg", "j0145191.jpg", "j0145196.jpg", "j0145198.jpg",
	"j0145199.jpg", "j0145203.jpg", "j0145204.jpg", "j0145205.jpg",
	"j0145209.jpg", "j0145213.jpg", "j0145216.jpg", "j0145217.jpg",
	"j0145219.jpg", "j0145220.jpg", "j0145221.jpg", "j0145222.jpg",
	"j0145223.jpg", "j0145225.jpg", "j0145227.jpg", "j0145229.jpg",
	"j0145231.jpg", "j0145233.jpg", "j0145239.jpg", "j0145255.jpg",
	"j0145256.jpg", "j0145257.jpg", "j0145258.jpg", "j0145259.jpg",
	"j0145260.jpg", "j0145261.jpg", "j0145262.jpg", "j0145263.jpg",
	"j0145264.jpg", "j0145265.jpg", "j0145267.jpg", "j0145269.jpg",
	"j0145270.jpg", "j0145275.jpg", "j0145281.jpg", "j0145282.jpg",
	"j0145284.jpg", "j0145287.jpg", "j0145296.jpg", "j0145298.jpg",
	"j0145300.jpg", "j0145301.jpg", "j0145302.jpg", "j0145315.jpg",
	"j0145316.jpg", "j0145317.jpg", "j0145321.jpg", "j0145323.jpg",
	"j0145324.jpg", "j0145325.jpg", "j0145327.jpg", "j0145331.jpg",
	"j0145332.jpg", "j0145333.jpg", "j0145334.jpg", "j0145335.jpg",
	"j0145336.jpg", "j0145337.jpg", "j0145338.jpg", "j0145342.jpg",
	"j0145344.jpg", "j0145345.jpg", "j0145347.jpg", "j0145349.jpg",
	"j0145350.jpg", "j0145351.jpg", "j0145352.jpg", "j0145353.jpg",
	"j0145354.jpg", "j0145355.jpg", "j0145356.jpg", "j0145358.jpg",
	"j0145359.jpg", "j0145360.jpg", "j0145361.jpg", "j0145363.jpg",
	"j0145365.jpg", "j0145368.jpg", "j0145370.jpg", "j0145372.jpg",
	"j0145373.jpg", "j0145375.jpg", "j0145376.jpg", "j0145377.jpg",
	"j0145378.jpg", "j0145379.jpg", "j0145380.jpg", "j0145382.jpg",
	"j0145383.jpg", "j0145385.jpg", "j0145387.jpg", "j0145389.jpg",
	"j0145393.jpg", "j0145394.jpg", "j0145395.jpg", "j0145397.jpg",
	"j0145398.jpg", "j0145399.jpg", "j0145401.jpg", "j0145402.jpg",
	"j0145411.jpg", "j0145412.jpg", "j0145415.jpg", "j0145417.jpg",
	"j0145420.jpg", "j0145421.jpg", "j0145422.jpg", "j0145426.jpg",
	"j0145427.jpg", "j0145428.jpg", "j0145429.jpg", "j0145430.jpg",
	"j0145431.jpg", "j0145432.jpg", "j0145434.jpg", "j0145436.jpg",
	"j0145438.jpg", "j0145439.jpg", "j0145440.jpg", "j0145441.jpg",
	"j0145442.jpg", "j0145443.jpg", "j0145444.jpg", "j0145446.jpg",
	"j0145447.jpg", "j0145448.jpg", "j0145449.jpg", "j0145450.jpg",
	"j0145451.jpg", "j0145452.jpg", "j0145453.jpg", "j0145454.jpg",
	"j0145455.jpg", "j0145456.jpg", "j0145457.jpg", "j0145458.jpg",
	"j0145459.jpg", "j0145460.jpg", "j0145462.jpg", "j0145464.jpg",
	"j0145465.jpg", "j0145466.jpg", "j0145467.jpg", "j0145468.jpg",
	"j0145469.jpg", "j0145470.jpg", "j0145471.jpg", "j0145472.jpg",
	"j0145473.jpg", "j0145474.jpg", "j0145475.jpg", "j0145476.jpg",
	"j0145477.jpg", "j0145478.jpg", "j0145479.jpg", "j0145480.jpg",
	"j0145481.jpg", "j0145482.jpg", "j0145483.jpg", "j0145484.jpg",
	"j0145485.jpg", "j0145486.jpg", "j0145487.jpg", "j0145488.jpg",
	"j0145489.jpg", "j0145490.jpg", "j0145491.jpg", "j0145492.jpg",
	"j0145493.jpg", "j0145494.jpg", "j0145495.jpg", "j0145496.jpg",
	"j0145497.jpg", "j0145498.jpg", "j0145499.jpg", "j0145500.jpg",
	"j0145501.jpg", "j0145502.jpg", "j0145504.jpg", "j0145505.jpg",
	"j0145506.jpg", "j0145508.jpg", "j0145509.jpg", "j0145510.jpg",
	"j0145511.jpg", "j0145512.jpg", "j0145513.jpg", "j0145514.jpg",
	"j0145515.jpg", "j0145517.jpg", "j0145518.jpg", "j0145519.jpg",
	"j0145521.jpg", "j0145522.jpg", "j0145523.jpg", "j0145524.jpg",
	"j0145525.jpg", "j0145526.jpg", "j0145527.jpg", "j0145528.jpg",
	"j0145529.jpg", "j0145531.jpg", "j0145532.jpg", "j0145533.jpg",
	"j0145534.jpg", "j0145535.jpg", "j0145536.jpg", "j0145537.jpg",
	"j0145538.jpg", "j0145539.jpg", "j0145540.jpg", "j0145541.jpg",
	"j0145542.jpg", "j0145544.jpg", "j0145546.jpg", "j0145547.jpg",
	"j0145551.jpg", "j0145552.jpg", "j0145553.jpg", "j0145554.jpg",
	"j0145555.jpg", "j0145556.jpg", "j0145557.jpg", "j0145558.jpg",
	"j0145559.jpg", "j0145560.jpg", "j0145561.jpg", "j0145562.jpg",
	"j0145563.jpg", "j0145564.jpg", "j0145565.jpg", "j0145566.jpg",
	"j0145567.jpg", "j0145568.jpg", "j0145571.jpg", "j0145572.jpg",
	"j0145573.jpg", "j0145574.jpg", "j0145575.jpg", "j0145576.jpg",
	"j0145577.jpg", "j0145578.jpg", "j0145579.jpg", "j0145581.jpg",
	"j0145582.jpg", "j0145583.jpg", "j0145584.jpg", "j0145585.jpg",
	"j0145586.jpg", "j0145587.jpg", "j0145588.jpg", "j0145589.jpg",
	"j0145592.jpg", "j0145594.jpg", "j0145595.jpg", "j0145596.jpg",
	"j0145597.jpg", "j0145598.jpg", "j0145599.jpg", "j0145600.jpg",
	"j0145601.jpg", "j0145602.jpg", "j0145603.jpg", "j0145604.jpg",
	"j0145605.jpg", "j0145606.jpg", "j0145607.jpg", "j0145608.jpg",
	"j0145609.jpg", "j0145610.jpg", "j0145612.jpg", "j0145613.jpg",
	"j0145614.jpg", "j0145615.jpg", "j0145616.jpg", "j0145617.jpg",
	"j0145618.jpg", "j0145619.jpg", "j0145620.jpg", "j0145621.jpg",
	"j0145622.jpg", "j0145623.jpg", "j0145624.jpg", "j0145625.jpg",
	"j0145626.jpg", "j0145627.jpg", "j0145628.jpg", "j0145630.jpg",
	"j0145631.jpg", "j0145632.jpg", "j0145633.jpg", "j0145634.jpg",
	"j0145635.jpg", "j0145637.jpg", "j0145638.jpg", "j0145639.jpg",
	"j0145640.jpg", "j0145641.jpg", "j0145643.jpg", "j0145645.jpg",
	"j0145646.jpg", "j0145647.jpg", "j0145648.jpg", "j0145649.jpg",
	"j0145650.jpg", "j0145651.jpg", "j0145652.jpg", "j0145653.jpg",
	"j0145654.jpg", "j0145655.jpg", "j0145656.jpg", "j0145657.jpg",
	"j0145658.jpg", "j0145660.jpg", "j0145661.jpg", "j0145662.jpg",
	"j0145663.jpg", "j0145666.jpg", "j0145667.jpg", "j0145668.jpg",
	"j0145669.jpg", "j0145707.jpg", "j0145713.jpg", "j0145717.jpg",
	"j0145719.jpg", "j0145737.jpg", "j0145740.jpg", "j0145741.jpg",
	"j0145743.jpg", "j0145748.jpg", "j0145751.jpg", "j0145752.jpg",
	"j0145754.jpg", "j0145766.jpg", "j0145768.jpg", "j0145773.jpg",
	"j0145774.jpg", "j0145775.jpg", "j0145778.jpg", "j0145780.jpg",
	"j0145784.jpg", "j0145785.jpg", "j0145786.jpg", "j0145787.jpg",
	"j0145792.jpg", "j0145794.jpg", "j0145796.jpg", "j0145797.jpg",
	"j0145798.jpg", "j0145799.jpg", "j0145801.jpg", "j0145802.jpg",
	"j0145803.jpg", "j0145804.jpg", "j0145806.jpg", "j0145807.jpg",
	"j0145808.jpg", "j0145810.jpg", "j0145811.jpg", "j0145812.jpg",
	"j0145813.jpg", "j0145814.jpg", "j0145815.jpg", "j0145817.jpg",
	"j0145818.jpg", "j0145819.jpg", "j0145821.jpg", "j0145822.jpg",
	"j0145823.jpg", "j0145824.jpg", "j0145825.jpg", "j0145826.jpg",
	"j0145828.jpg", "j0145831.jpg", "j0145832.jpg", "j0145833.jpg",
	"j0145834.jpg", "j0145837.jpg", "j0145838.jpg", "j0145839.jpg",
	"j0145841.jpg", "j0145842.jpg", "j0145843.jpg", "j0145845.jpg",
	"j0145846.jpg", "j0145847.jpg", "j0145848.jpg", "j0145849.jpg",
	"j0145851.jpg", "j0145852.jpg", "j0145853.jpg", "j0145854.jpg",
	"j0145855.jpg", "j0145857.jpg", "j0145858.jpg", "j0145861.jpg",
	"j0145862.jpg", "j0145863.jpg", "j0145865.jpg", "j0145866.jpg",
	"j0145867.jpg", "j0145868.jpg", "j0145869.jpg", "j0145870.jpg",
	"j0145872.jpg",	"j0145873.jpg",	"j0145874.jpg",	"j0145875.jpg",
	"j0145876.jpg",	"j0145877.jpg",	"j0145878.jpg",	"j0145879.jpg",
	"j0145880.jpg",	"j0145881.jpg",	"j0145882.jpg",	"j0145885.jpg",
	"j0145886.jpg",	"j0145889.jpg",	"j0145891.jpg",	"j0145893.jpg",
	"j0145895.jpg",	"j0145896.jpg",	"j0145897.jpg",	"j0145898.jpg",
	"j0145899.jpg",	"j0145900.jpg",	"j0145901.jpg",	"j0145902.jpg",
	"j0145903.jpg",	"j0145904.jpg",	"j0145930.jpg",	"j0145931.jpg",
	"j0145940.jpg",	"j0148788.jpg",	"j0148810.jpg",	"j0148835.jpg",
	"j0148837.jpg",	"j0148849.jpg",	"j0148899.jpg",	"j0148918.jpg",
	"j0148920.jpg",	"j0148939.jpg",	"j0148947.jpg",	"j0148953.jpg",
	"j0148954.jpg",	"j0149187.jpg",	"j0149201.jpg",	"j0149216.jpg",
	"j0149245.jpg",	"j0149259.jpg",	"j0149261.jpg",	"j0149270.jpg",
	"j0149277.jpg",	"j0149280.jpg",	"j0149283.jpg"
const size_t urls = sizeof (files) / sizeof (*files) - 1;
int RandLink()
	int Num;
	srand ((unsigned)time(NULL));
	Num = rand() % urls;
	return Num;
int main() {
	printf("%s", files[RandLink()]);
	return 0;

Here I am putting up a code sample to print out a stylesheet in your Perl CGI
scripts. Very easy to use. I love this type of thing when I find it. I tried to
have the script load in the stylesheet from the file styles/style.css but it
does not seem to work. So I found this way of doing it by reading the CGI man
page. Now I have it.

		background-color: #003333;
		background-color: #000033;
	TD {
		background-color: #003333;
		border-style: ridge;
		border-width: 1px;
		border-color: silver;
	P {
		font-size: 12pt;
		font-face: Helvetica;
		font-weight 100;
		color: #FFFFFF;
	H1 {
		color: #FFFF3F;
		border-style: ridge;
		border-width: 1px;
		border-color: silver;
		background-color: #003333;
		color: #FFFFFF;
		font-face: Times;
		font-size: 12pt;
print $query->start_html(-title=>'Bejiitas Wrath`s Guestbook.',
	-meta=>{'keywords'=>'Blog Doom2 Linux Quake Doom3',
		'copyright'=>'Copyright 2007 John Cartwright.',
		'definition'=>'My Blog Script.',
		'description'=>'CGI Guestbook script.'},

A C program to load a random fortune. Put it in ~/bin and run it in your
~/.profile or ~/.bashrc

* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
* Description: Program to run fortune(1)
* Author: Homer Simpson
* Created at: Sat Nov 11 16:23:21 EST 2006
* Computer: linux-sfrk
* System: Linux on i686
* Copyright (c) 2006 Homer Simpson  All rights reserved.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <string.h>
const char* x[] = {
	"limerick", "fortunes2", "linuxcookie",
	"freebsd-tips", "osfortune", "startrek",
	"zippy", "debian-hints"
const size_t FORTUNES = sizeof(x)/sizeof(*x) - 1;
int cool(int Size) {
	int k;
	k = 0;
	k = rand() % Size;
	return k;
int main()
	execlp("/usr/bin/fortune", x[cool(FORTUNES)], "-l", NULL, NULL);
	return 0;

Random Number program.

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int cool(void) {
	int i;
	int k;
	i = 32;
	k = 0;
	k = rand() % i;
	return k;
int main() {
	printf("%i", cool());
	return 0;

Reading in a text file.

#include <stdlib.h>
#include <stdio.h>
#define log "tables.htm"
int main()
	FILE *f;
	char Kyo[40];
	int Fsize;
	f = fopen(log, "r");
	Fsize = sizeof(f);
	if(!f) {
		printf("Sorry, I cannot open: %s.\n", log);
	} else {
		while (feof(f) != 1 && Fsize < 32768) {
			fgets(Kyo, Fsize, f);
			printf("%s", Kyo);
		printf("\n\x78*----* Done. *----*\x78\n");
return 0;

Counting the length of a text string.

#include <stdlib.h>
#include <string.h>
#define MSG "Hello Doctor, let's get back to the TARDIS!"
int main() {
	int g;
	g = strlen(MSG);
	if (g < 1) {
		printf("The string is not very long!\n");
	} else {
		printf("The length of the string `MSG' is: %i characters.\n", g);
	return 0;

This is a backup program which will backup the contents of a directory and
output it to a tgz file.

#!/usr/bin/perl -W
use strict;
use POSIX ("strftime");
# A script to backup some files.
my $homedir = "$ENV{'HOME'}";
my $user = $ENV{'LOGNAME'};
my $date = strftime("%A-%d-%B-%Y-%H-%M-%S", localtime);
print "Which directory do you want to backup?\n";
chomp(my $dir = <STDIN>);
if(!$dir) {
	print "No Directory selected!\n";
} else {
	my $target="$homedir\/$dir";
	my $file = "$homedir\/$user-$date.tgz";
	system("tar -cvf $file $target");
	print "\n\nSuccessful backup of directory: $dir.\n";

This is another program, in standard C this time. It just prints out the
current time & date.

#include <time.h>
#include <stdio.h>
#define format "The time and date is: %A %d %B %Y. The time is: %T, %Z."
int main() {
	struct tm *ptr;
	time_t tm;
	char str[60];
	tm = time(NULL);
	ptr = localtime(&tm); // Getting the seconds since Epoch.
	strftime(str, 100, format, ptr); // And feeding it into strftime.
	Formatting the strftime string.
	printf("%s\n", str);

This is another way you can use the strftime formatting in your
scripts. Revised: Friday, April 08 2005.

use POSIX qw/strftime/;
$date = strftime "%T - %A %d %B %Y", localtime;
print "$date\n";

This code sample will print out an image to the browser. This could
be very useful if you point a web form to the script and this allows
you to have a CGI displayer of your images.

$file = "hello.jpg";
print "Content-Type: multipart/x-mixed-replace;boundary=myboundary\n\n";
print "--myboundary\n";
print "Content-Type: image/jpeg\n\n";
	open(GOATSE,"$file" || die "I cannot open the image $file -\n- $!");
	print <GOATSE>;
	print "\n--myboundary\n";

This code sample below prints out the time and date using
/bin/date. Updated! as of 17/12/2004. Note, this sample uses strftime(3)
formatting. You just re-arrange the %A %b %G Elements to change the date-time
format. type man strftime to get more information.

use strict;
use warnings;
my $date_command = "/bin/date"; # Using the date command.
my $date = `$date_command +"%H:%M:%S %A-%B-%d-%G -- (%Z)"`; chop($date);
print "$date\n";

And this is some sample code from the latest version of my Viewblog CGI. To
print the date and time.

my @Days = ('Sunday','Monday','Tuesday',
my @Mon1 = ('January','February','March',
my ($Sec,$Min,$Hour,$MDay,$Mon,$Year,$WkDay) = (localtime)[0,1,2,3,4,5,6];
$Year += 1900;
if($Sec < 10) {
    $Sec = "0$Sec"
if($Min < 10) {
    $Min = "0$Min"
if($Hour < 10) {
    $Hour = "0$Hour"
$date = "$Hour:$Min:$Sec - $Days[$WkDay] $MDay $Mon1[$Mon] $Year";

Valid HTML 4.01 Strict