• Forum
  • Lounge
  • Just found some really old code on a lap

 
Just found some really old code on a laptop

Pages: 12
And by old, I mean this was when I was first learning to program. It made me feel all nostalgic and such. Here it is:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
int** toListN(int* lst, int length, int n) {
    int** listn;
    int lengthn = length/n;
    listn = new int[n];
    for(int i = 0; i < n-1; i++) {
            listn[i] = new int[lengthn]
    }
    if((length%n) == 0) {
        listn[n] = new int [lengthn]
    } else {
        listn[n] = new int[lenghtn+(length%n)]
    }
    for(int i = 0; i < length; i++) {
        if(i>lengthn) {
            listn[n] = lst[i];
        } else {
            listn[i%n] = lst[i];
        }
    }
    return listn;
}


Oh how far I've come...

Anyways, share some of your oldest code!

edit: fixed error in code. It was glaring at me, I couldn't just leave it there :P
Last edited on
1
2
3
4
5
6
#include <iostream>

int main(){
    std::cout << "Yo!" << std::endl;
    return 0;
}


=P
Here's a bit I still see hanging around.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
* Program......: CENTER.PRG
* Author.......: 
* Date.........: June 26, 1989  8:21 pm
* Purpose......: Function to center strings by stuffing with blank spaces.
* Syntax.......: CENTER(<expC>,<expN>)
* Return.......: <expC> centered in a line with a length <expN>.

FUNCTION Center

PARAMETERS stng,mlen

IF TYPE("mlen") <> "N"
	mlen = 80
ENDIF

RETURN SUBSTR(STUFF(SPACE(mlen),(mlen-(LEN(stng)))/2,LEN(stng),stng),1,mlen)

* EOF() CENTER.PRG


(You didn't say it had to be C/C++).
unfortunately my oldest code is gone after a couple of failed hdds. I do remember when i was learning c how i forgot you had to scan with scanf (yuck) and instead tried to take input with printf. when i was first writing html i wrote this: http://www.chambers-family.com/homepage.html (dont worry ive very much improved since then)
Before I knew what a std::map was:
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
unsigned int FindUVar(LPRDATA rdPtr, string UVarName)
{
	unsigned int i;
	for(i = 0; i < rdPtr->UIndex->size(); i++)
	{
		if((*rdPtr->UIndex)[i] == UVarName)
		{
			return(i);
		}
	}
	rdPtr->UIndex->resize(rdPtr->UIndex->size()+1, UVarName);
	rdPtr->UVars->resize(rdPtr->UVars->size()+1, 0);
	return(i);
}

unsigned int FindSVar(LPRDATA rdPtr, string SVarName)
{
	unsigned int i;
	for(i = 0; i < rdPtr->SIndex->size(); i++)
	{
		if((*rdPtr->SIndex)[i] == SVarName)
		{
			return(i);
		}
	}
	rdPtr->SIndex->resize(rdPtr->SIndex->size()+1, SVarName);
	rdPtr->SVars->resize(rdPtr->SVars->size()+1, 0);
	return(i);
}
https://github.com/LB--/AdvancedInt64-Object/blob/master/Main.cpp#L44-L72
Ah! My eyes! ;p

Quite a large snippet:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
class Unit : public Object
{
	public:
		//virtual int Init()             {return 0;}

		void SetClipsDefault()
		{
			int _x = 0;
			int _y = 0;

			// Start to load the clips from the images
			for(int c = 0; c < 4; c++)
			{
				DClips[c].x = _x;
				DClips[c].y = _y;

				DClips[c].w = PLYRG_W;
				DClips[c].h = PLYRG_H;

				_x += PLYRG_W;
			}

			_x = 0;
			_y = PLYRG_H;

			for(int c = 0; c < 4; c++)
			{
				LClips[c].x = _x;
				LClips[c].y = _y;

				LClips[c].w = PLYRG_W;
				LClips[c].h = PLYRG_H;

				_x += PLYRG_W;
			}
			_x = 0; 
			_y += PLYRG_H;

			for(int c = 0; c < 4; c++)
			{
				RClips[c].x = _x;
				RClips[c].y = _y;

				RClips[c].w = PLYRG_W;
				RClips[c].h = PLYRG_H;

				_x += PLYRG_W;
			}
			_x = 0;
			_y += PLYRG_H;

			for(int c = 0; c < 4; c++)
			{
				UClips[c].x = _x;
				UClips[c].y = _y;

				UClips[c].w = PLYRG_W;
				UClips[c].h = PLYRG_H;

				_x += PLYRG_W;
			}

		}

		void HandleAnimDefault()
		{
			// If the player is moving, add one value to the delay
			if(moving == true)
			{
				delay++;
			}

			else
			{
				// If he/she isn't moving, make sure the player
				// doesn't get animated
				delay = 0;
			}

			// If the delay reaches the point where it
			// needs to add a frame, go to the next frame
			// and reset the delay
			if(delay == delaychange)
			{
				frame++;
				delay = 0;
			}

			// If the frame is larger than the frames in the
			// image, reset the frame to 0
			if(frame > 3)
			{
				frame = 0;
			}
		}

		void HandleEnergy_HealthRegen()
		{
			EnergyRegenT++;
			if(EnergyRegenT > 175)
			{
				Energy += 1;
				EnergyRegenT = 0;
			}
			if(Energy > MaxEnergy) {Energy = MaxEnergy;}

			HealthRegenT++;
			if(HealthRegenT > 250)
			{
				Health += 1;
				HealthRegenT = 0;
			}
			if(Health > MaxHealth) {Health = MaxHealth;}
		}

		SDL_Surface* getGraphic() const{return Graphic;}

		void setCollided(bool collision) {Collided = collision;}
		void setPosition(int pos)     {Position = pos;}

		// Getters
		int getEnergy   () const{return Energy;}
		int getMaxEnergy() const{return MaxEnergy;}

		int getPosition()  const{return Position;}

		bool getCollided() const{return Collided;}

	protected:
		std::string Name;
		int Energy;    // How much energy a unit has
		int MaxEnergy; // The maximum energy value

		// Regeneration variables
		int EnergyRegenT;
		int HealthRegenT;

		bool Collided;

		// What frame the player is on.
		int frame;
		bool action;     // If the player is preforming an action
		int delaychange; // The time the player delay changes

		int delay;       // The current value of the delay
		bool moving;     // Check if the player is moving
		int Position;    // The position the player is

		// Animations
		/*Animation LeftAnim,
		          RightAnim,
		          UpAnim,
		          DownAnim;*/

		// Animation Clips
		SDL_Rect LClips[4];
		SDL_Rect RClips[4];
		SDL_Rect UClips[4];
		SDL_Rect DClips[4];

		// Defense value
		int defense;

		// The graphic
		SDL_Surface* Graphic;
};
Last edited on
@jlb
What language is that?
dBase II
Its actually on here :/ glad I stay anonymous.

Im a bit better now tho.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>
#include <string>

using namespace std;

class fatty{
public:
int name;
int pancake;

};
int main()

{

    int highcake = 0;
    string namebox;
    fatty fat [8];
    for (int q =0; q > 8; q++)
    {
        fatty fat [q];
        cout << "enter fatties name "<<endl;
        cin >> fat[q].name;
        cout << "how many pancakes has the fat bastard eaten?" << endl;
        cin >> fat[q].pancake;
        if (fat [q]pancake < highcake)
         {
         highcake = fat[q].pancake;
         namebox = fat [q].name;
        }
    }

cout << "fat bastard called " << namebox << "ate the most cake ( " << highcake << " pancakes )" <<endl;



return 0;
}
int name; It's funny because a lot of people actually do things like these because their instructors teach them int first and they don't realize it stands for "integer." Also, I'm assuming you never passed the pancake gluten :P since your loop never gets executed.
Last edited on
I've advanced a little since those days and now I can write programs that tell me who actually ate all the pancakes in real life...

oddly enough however, I don't understand this code :/
oddly enough however, I don't understand this code :/

Considering it doesn't compile and has lots of logic errors that would make sense.
I'm just learning C++. Here's what I could accomplish in two days and 100 pages through my first C++ book; You can tell what came from the ncurses manual by the /* */ comments... I hate "hello world" programs. Looking forward to classes, vectors, and how to use cmake. It compiles with: g++ main.cpp -m32 -lpanel -lncurses

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include <iostream>
#include <ctime>
#include <cstring>
#include <sstream>
#include <time.h>
#include <cstdlib>
// Ncurses
#include <ncurses.h>
#include <menu.h>
#include <panel.h>

using namespace std;

int y = 10, x = 25;
static time_t start;
static time_t timer_diff;
static int timer_diff_m;
static int timer_diff_h;

int status = 0;

WINDOW *my_wins[0];
PANEL  *my_panels[0];

char input[100];

char c_name[100];
char c_company[100];
char c_details[1000];

void basics()
{
    clear();
    mvprintw( 0, 0, "(Type 'quit' to exit)" );
    mvprintw( 5, 0, "start) (Re)Start Timer" );
    mvprintw( 6, 0, "stop) Check Timer" );
    mvprintw( 7, 0, "n) New Ticket" );
    if ( start != 0 ) { mvprintw( 5, x, "Timer started" ); }

    if ( timer_diff_m != 0 ) { mvprintw( 6, 25, "Time: %d hours : %d minutes", timer_diff_h, timer_diff_m ); }

    mvprintw( y, x, "Enter option: " ); // ncurses print (uses y, x for coordinates)
    update_panels();
    doupdate();
}

void basics2()
{
    clear();
    mvprintw( 0, 0, "(Type 'quit' to exit)" );
    mvprintw( 5, 0, "start) (Re)Start Timer" );
    mvprintw( 6, 0, "stop) Check Timer" );

    if ( start != 0 ) { mvprintw( 5, x, "Timer started" ); }

    if ( timer_diff_m != 0 ) { mvprintw( 6, 25, "Time: %d hours : %d minutes", timer_diff_h, timer_diff_m ); }

    if (c_name != 0) { mvwprintw( my_wins[0], 1, 1, "Client Name: %s", c_name ); } // ncurses print (uses y, x for coordinates)

    update_panels();
    doupdate();
}

void exec_option( char option[100] )
{
    int yy = y, xx = x;

    // Start timer
    if ( strcmp( option, "start" ) == 0 ) {
        start = time(0);
        basics();
        if ( status == 1 ) { basics2();}
    }

    // Stop timer
    if ( strcmp( option, "stop" ) == 0 ) {
        time_t end = time(0);
        timer_diff = end - start;

        if ( timer_diff >= 60 ) {
            timer_diff_m = ((int)timer_diff / 60) % 60; // convert to minutes
            timer_diff_h = ((int)timer_diff / 60 / 60) % 24; // convert to hours

        } else if ( (timer_diff > 0) && (timer_diff < 60) ) { timer_diff_h = (int)0; timer_diff_m = (int)1; }

        basics();
        if ( status == 1 ) { basics2();}
    }

    // Change to the Ticket panel
    if ( strcmp( option, "n" ) == 0 ) {

        status = 1;
        int lines = 30, cols = 60, yy = 12, xx = 20, i;

        /* Create windows for the panels */
        my_wins[0] = newwin(lines, cols, yy, xx);

        /* Create borders around the windows so that you can see the effect of panels */
            box(my_wins[0], 0, 0);

        /* Attach a panel to each window */ 	/* Order is bottom up */
        my_panels[0] = new_panel(my_wins[0]); 	/* Push 0, order: stdscr-0 */

        /* Update the stacking order. 2nd panel will be on top */
        update_panels();

        /* Show it on the screen */
        doupdate();

        mvwprintw( my_wins[0], 1, 1, "Client Name: " );
        wgetstr( my_wins[0], c_name);

        mvwprintw( my_wins[0], 3, 1, "Company Name: " );
        wgetstr( my_wins[0], c_company);

        mvwprintw( my_wins[0], 5, 1, "Details: " );
        wgetstr( my_wins[0], c_details);
    }
}

int main ()
{
    initscr();     // creates stdscr
    cbreak(); // debug
    keypad(stdscr, TRUE);
    basics();

    while ( strcmp( input, "quit" ) != 0 )   // ESC (27) to exit
    {
        // Option List
        if (status == 1) {
            wgetstr( my_wins[0], input );
        } else { getstr( input ); }
        exec_option( input );
    }

    endwin();      // ncurses end
    return 0;
}
I think you mean "console programs" and not "hello world programs".
http://www.cplusplus.com/articles/G13hAqkS/
I can't tell whether your code is ugly because it's ugly, because curses is ugly, or because your style is against my personal preferences.
I think you mean "console programs" and not "hello world programs".

No, I mean "hello world" programs. I like to code examples that I would actually use- helps me learn better.


I can't tell whether your code is ugly because it's ugly, because curses is ugly, or because your style is against my personal preferences.

Maybe the second, definitely the first with a dash of the third. I'm still adjusting my style; I've only been writing for several days. I used curses because I wanted to see how it worked and what I could do with it.


Thanks for the link; I'll browse the articles section.
No, I mean "hello world" programs.


I've heard tell that John Carmack's hello world for a new technology is implementing Quake.
A bach game called quiziers.
(note: where it says who made it I blanked it out for personal information)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
@echo off
color 0a
:menu
cls
color 0a
echo welcome!
echo 1) start game

echo 2) info
echo 3)exit
set /p men=

if %men% == 1 goto game
if %men% == 2 goto info/gam
if %men% == 3 exit
cls

:info/gam
cls
color 0a
echo quizers.bat was made by: *********** AND ************
echo os requermets
echo windows 7
echo windows xp
echo windows vista
echo file size 4k bytes
echo ver 1.4
echo go to menu?(y/n)
set /p gt=
if %gt% == y goto menu
if %gt% == n goto info/gam

 
:game
cls
color 0a
echo hello contestant
echo start the quiz?(y/n)
set /p dot=

if %dot% == y goto start/game
if %dot% == n goto menu



:start/game
cls
color 0a
echo answer questions to move on.
echo what programing langege is this?
echo 1)c
echo 2)dos programing
echo 3)java
echo 4) hint!
set /p an=

if %an% == 1 goto wrl
if %an% == 2 goto crl
if %an% == 3 goto wrl
if %an% == 4 goto hin1

:wrl
cls
color 0c 
echo wrong!
echo start over?(1/2)
set /p wer=

if %wer% == 1 goto start/game
if %wer% == 2 goto wrl
if %wer% == yy goto start/game
if %wer% == nn goto start/game
if %wer% == 11 goto start/game
if %wer% == 22 goto wrl

:crl
cls
echo correct!!
echo move on?(1/2)
set /p mov=

if %mov% == 1 goto start/gam2
if %mov% == 2 goto start/gam

:hin1
cls
echo hint: it deos not start with a j
echo go back?(1/2)
set /p gst=

if %gst% == 1 goto start/game
if %gst% == 2 goto hin1 
if %gst% == yy goto start/game  
if %gst% == nn goto start/game
if %gst% == 11 goto start/game
if %gst% == 22 goto hin1
if %gst% == y goto start/game
if %gst% == n goto start/game


:start/gam2
cls
echo when did starwars come out?
echo 1)2005
echo 2)1977
echo 3)1983
echo 4)hint
set /p gol=

if %gol% == 1 goto wrl2
if %gol% == 2 goto crl2
if %gol% == 3 goto wrl
if %gol% == 4 goto hin2
if %gol% == yy goto wrl

:Wrl2
cls
color 0c
echo wrong, this one is in 3d
echo start over(1/2)
set /p gto=

if %gto% == 1 goto start/game
if %gto% == 2 goto wrl2
if %gto% == yy goto start/game
if %gto% == nn goto start/game
if %gto% == 11 goto start/game
if %gto% == 22 goto wrl2

:hin2
cls
echo 2 answrs are right,but one is in 3d
echo go back?(1/2)
set /p gom=

if %gom% == 1 goto start/gam2
if %gom% == 2 goto hin2
if %gom% == yy goto start/gam2
if %gom% == nn goto start/gam2
if %gom% == 11 goto start/gam2
if %gom% == 22 goto hin2
:crl2
cls
echo correct!!
echo move on?(y/n)
set /p mov=

if %mov% == y goto start/gam3
if %mov% == n goto start/gam

  
:start/gam3
cls
echo what is 11x11=
echo 1)44
echo 2)22
echo 3)121
echo 4)hint
set /p trr=

if %trr% == 1 goto wrl
if %trr% == 2 goto wrl 
if %trr% == 3 goto crl3
if %trr% == 4 goto hin3
if %trr% == yy goto wrl

:crl3
cls
echo correct!!!
echo almost there
echo advance(1/2)
set /p frd=

if %frd% == 1 goto start/gam4
if %frd% == 2 goto start/gam3
if %frd% == 11 goto start/gam4
if %frd% == 22 goto start/gam3

:hin3
cls
echo hint:its not 2 
echo go back?(1/2)
set /p gr=

if %gr% == 1 goto start/gam3
if %gr% == 2 goto hin3
if %gr% == yy goto start/gam3
if %gr% == nn goto start/gam3
if %gr% == 11 goto start/gam3
if %gr% == 22 goto hin3

:start/gam4
cls
echo what is the day we got our independince?
echo 1)aug 6
echo 2)may 23
echo 3)july 4
echo 4)hint
set /p det=

if %det% == 1 goto wrl
if %det% == 2 goto wrl
if %det% == 3 goto crl4
if %det% == 4 goto hin4

:crl4
cls
echo you are correct!
echo go to next level or bouns level?
echo press 1/2 for next level,press b for bouns level  
set /p c=

if %c% == 1 goto start/gam5
if %c% == 2 goto start/gam4
if %c% == b goto bone

:hin4
cls
echo  it is right behind augest
echo go back?(1/2)
set /p gt=

if %gt% == 1 goto start/gam4
if %gt% == 2 goto hin4

:bone
cls
echo 89/4=
echo 1)20.5
echo 2)22.25
echo 3)30.3
set /p tgb=

if %tgb% == 1 goto bonw
if %tgb% == 2 goto bonc
if %tgb% == 3 goto bonw

:bonw
cls
echo wrong
echo goto next level 5?(y/n)
set /p hk=

if %hk% == y goto start/gam5
if %hk% == n goto start/gam5

:bonc
cls
echo correct
echo go to next level?(y/n)
set /p rfv=

if %rfv% == y goto start/gam5
if %rfv% == n goto bonc

:start/gam5
cls
echo what is the year minecraft came out?
echo 1)2010
echo 2)2009
echo 3)2012
echo 4)hint
set /p weer=

if %weer% == 1 goto wrl
if %weer% == 2 goto crl5
if %weer% == 3 goto wrl
if %weer% == 4 goto hin5

:crl5
cls
echo correct
echo go to next level?(y/n)
set /p tyu=

if %tyu% == y goto start/gam6
if %tyu% == n goto crl5

:hin5
cls
echo go to mine craft forums
echo press p to go to minecraft.net
set /p rfgh=

if %rfgh% == y goto start/gam5
if %rfgh% == n goto crl5
if %rfgh% == p goto min

:min
cls
start http://www.minecraft.net
echo go back
set /p yhj=

if %yhj% == y goto hin5
if %yhj% == n goto min 

:start/gam6
echo when was this game made?
echo
It can't have been made very long ago since it has a link to Minecraft in it. Minecraft didn't exist when I wrote the code I posted.
The oldest thing I found on my computer is from 1988. It's a fast text searching program with a nice user interface using text-based windows. All written in C.

I should have some files from grad school here somewhere. Those would go back to 1986-87.

Before that I have some nice programs for the the HP-41C calculator from the late 70s/early 80s. :)
Do share, dhayden?
Pages: 12