[more code]

more code! list of contents is below!

most code here should be in C++, I just post random snippets here...

many thanks to hilite.me for the syntax hiliting

permutations solution for cprogramming.com WARNING:HIGHLY MESSY
integer - to - english converter for cprogramming.com (half working, quit halfway
source code line counter class that skips empty lines and comments
#include <iostream>
#include <string.h>

using namespace std;

void clr(char* a, int l)
{
    for(int i=0; i<l; i++)
    *(a+i)=NULL;
}

char *out=NULL;

void permute(char *list, bool parent, int sl=0, int depth=0)
{
    int i;
    if(parent)
    {
        sl=strlen(list);
        out=new char[strlen(list)];
        clr(out, strlen(list));
    }
    for(i=0; *(list+i); i++)
    {
        char* nl=new char[strlen(list)-1];
        clr(nl, strlen(list)-1);
        for(int k=0, j=0; *(j+list); j++)
        {
            if(j!=i)
            {
                *(k+nl)=*(j+list);
                k++;
            }
            *(k+nl)=NULL;
            *(k+nl+1)=NULL;
        }
        out[depth]=*(list+i);
        permute(nl, false, sl, depth+1);
        if((depth+1)>=sl)
            cout << out << endl;
    }
}


int main(int argc, char *argv[])
{
    out=NULL;
    cout << "Solution for cprogramming.com Challenger Question" << endl;
    cout << "All permutations : " << endl;
    if(argc==1)
    {
        cout << "Usage : permute <string";
        return 0;
    }
    permute((char*)argv[1],true);
    return 0;
}
#include <iostream>

using namespace std;

char engl_units[][20]={"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
char engl_teens[][20]={"","eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"};
char engl_tens[][20]={"","ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"};
char engl_bigs[][20]={"","hundred", "thousand", "million", "billion"};

/*
class englnum{
public:
    int num;

}*/

typedef struct numexp{
    int bill, mill, hthou, tthou, thou, hund, ten, one;
};

numexp expandnumber(int num){
    numexp e;
    int s=0;
    s+=e.one=(num%10);
    s+=e.ten=((num%100)-s);
    s+=e.hund=((num%1000)-s);
    s+=e.thou=((num%10000)-s);
    s+=e.tthou=((num%100000)-s);
    s+=e.hthou=((num%1000000)-s);
    s+=e.mill=((num%1000000000)-s);
    s+=e.bill=(num-s);
    return e;
}

void outenglishvalue(int a)
{
    if(!a)
        return;
    if(a<10)
    {
        cout << engl_units[(a)] << ' ';
        return;
    }
    if((a>10)&&(a<20))
    {
        cout << engl_teens[a-11] << ' ';
        return;
    }
    if(a<100)
    {
        cout << engl_tens[(a/10)] << ' ';
        return;
    }
    if(a<1000)
    {
        cout << engl_units[(a/100)] << ' ';
        cout << "hundred ";
        return;
    }
    if(a<10000)
    {
        cout << engl_units[(a/1000)] << ' ';
        cout << "thousand ";
        return;
    }
    if((a>10000)&&(a<20000))
    {
        cout << engl_teens[(a/1000)-11] << ' ';
        cout << "thousand";
        return;
    }
    if(a<100000)
    {
        cout << engl_tens[(a/10000)] << ' ';
        cout << "thousand ";
        return;
    }
    if(a<1000000)
    {
        cout << engl_units[(a/100000)] << ' ';
        cout << "hundred thousand ";
        return;
    }
    if((a>=1000000) && (a<10000000))
    {
        cout << engl_units[(a/1000000)] << ' ';
        cout << "million ";
        return;
    }
    if((a<20000000) && (a>10000000))
    {
        cout << engl_teens[(a/1000000)-11] << ' ';
        cout << "million ";
        return;
    }
    if((a>10000000)&&(a<100000000))
    {
        cout << engl_tens[(a/10000000)] << ' ';
        cout << "million ";
        return;
    }
    if((a>100000000)&&(a<1000000000))
    {
        cout << engl_units[(a/100000000)] << ' ';
        cout << "hundred million ";
        return;
    }
    if(a>=1000000000)
    {
        cout << engl_units[(a/1000000000)] << ' ';
        cout << "billion ";
        return;
    }

}

void outenglish(numexp e)
{
    if(e.bill)
    {
        outenglishvalue(e.bill); //cout << ",";
    }
    if(e.mill)
    {
        outenglishvalue(e.mill); //cout << ",";
    }
    if(e.hthou)
    {
        outenglishvalue(e.hthou); //cout << ",";
    }
    if((e.tthou==10000)&&(e.thou))
    {
        int i=e.tthou+e.thou;
        outenglishvalue(i/1000);
        cout << "thousand ";
    }
    else
    {
 /*       if(e.tthou && e.thou)
        {
            int i=e.thou+e.thou;
            outenglishvalue(i/1000);
            cout << "thousand";
        }*/
 //       else{
            if(e.tthou)
            {
                outenglishvalue(e.tthou); //cout << ",";
            }
            if(e.thou)
            {
                outenglishvalue(e.thou); //cout << ",";
            }
  //      }
    }
    if(e.hund)
    {
        outenglishvalue(e.hund); //cout << ",";
    }
    if(e.ten)
    {
        outenglishvalue(e.ten); //cout << ",";
    }
    if(e.one)
    {
        outenglishvalue(e.one); //cout << ".";
    }
}

int main()
{
    cout << "Solution for the intermediate challenge" << endl;
    cout << "enter number to translate" << endl;
    int in;
    cin >> in;
    numexp n=expandnumber(in);
    outenglish(n);
    return 0;
}
		
#ifndef SRCPARSE_H
#define SRCPARSE_H
#include <cstring>
#include <cstdlib>
#include <iostream>

class srcparse{
private:
	char* data;
public:
	typedef struct{
		int chartotal;
		int linetotal;
		int linecode;
	}stats;
	srcparse()
	{
		data=NULL;
	}
	stats parse(char* data);
protected:
};
#endif
/******************** SRCPARSE.CPP *********************/
#include "srcparse.h"

srcparse::stats srcparse::parse(char* data)
{
	/* srcparse::parse */
	/* info: 
	gets statistics for a source file, skipping '//' and '/* .. *.. comment blocks.
	sets linecount to 1 and starts from the beginning. when '//' is encountered, 
	skip until '\n' is encountered. when '/*' is encountered, skip until comment block close
	is found. every time newline is encountered, increment newline counter, etc.
	*/
	const char cr=0x0D; // CR = 13
	const char lf=0x0A;	// LF = 10
	bool inLineComment=false;
	bool inBlockComment=false;
	bool lineHasChars=false; // this flag is set to true when meaningful chars have been found.
	stats rStats;
	rStats.chartotal=0;
	rStats.linecode=0;
	rStats.linetotal=0;
	for(int i=0; data[i]; i++, rStats.chartotal++)
	{
		if(data[i]=='/' && data[i+1]=='*' && inBlockComment==false)
		{
			// looks like we hit a block comment
			inBlockComment=true;
			continue;
		}
		if(data[i]=='*' && data[i+1]=='/' && inBlockComment==true)
		{
			// looks like we hit a block comment closer
			inBlockComment=false;
			continue;
		}
		if(data[i]=='/' && data[i+1]=='/' && inLineComment==false && inBlockComment==false)
		{
			inLineComment=true;
			continue;
		}
		if(data[i]!=' ' && data[i]!='\t' && data[i] && data[i]!='\n' && lineHasChars==false && inBlockComment==false && inLineComment==false)
			lineHasChars=true;
		if(data[i]==cr || data[i]==lf)
		{
			/* here, it is important to make allowance for both UNIX and DOS format text.
			UNIX has CR+LF while DOS only has LF */
			if(data[i]==cr && data[i+1]==lf)
			{
				/* cr+lf means it's a *nix file*/
				i+=2;
			}
			else if(data[i]==lf)
			{
				/* lf only means it's a DOS file*/
				i++;
			}
			rStats.linetotal++;
			if(!inBlockComment && lineHasChars)
				rStats.linecode++;	// only increment code lines if we're not in a comment and the line
									// has meaningful chars
			lineHasChars=false;
			inLineComment=false;
		}
		if(data[i]==NULL)
		{
			rStats.linetotal++;
			if(!inBlockComment && lineHasChars)
				rStats.linecode++;	// only increment code lines if we're not in a comment and the line
									// has meaningful chars
			lineHasChars=false;
			inLineComment=false;
		}
	}
	return rStats;
}