Joe Shmoe 33 Light Poster

If I have an EXE file what command can I use to link a RES file into the EXE!? I have tried many different linker programs and can't figure out how to do this simple task with any of them.

Joe Shmoe 33 Light Poster

It looks like you made no changes to the code. You just added comments. You realize that the function is not working, and that's why I need help changing or completely rewriting. I just put it here to make it clearer what I was trying to do. It does not work.

Joe Shmoe 33 Light Poster

I think you may need to forward the ports on your router.

Joe Shmoe 33 Light Poster

Oh yeah. Please don't hijack other threads,

Joe Shmoe 33 Light Poster
Joe Shmoe 33 Light Poster

I am trying to alphabetize by generating a weight of a word, saving those numbers, and then comparing which numbers are greater. Don't ask me why I need to do this way.

So I am trying to come up with a function that calculates the value of a certain word. I am using the asc function to get the ascii value, but I am not good enough at math to figure out how to calculate this.

Here is what I have. It's written in VB, but I really don't care what language, I just want to understand the algorithm.

Dim byt As Integer
Dim acc As Integer

If txt = "" Then
    lbl = "0"
Else
    For i = 1 To Len(txt)
        byt = Asc(Mid(txt, i, 1))
        acc = acc + (byt / i)
    Next i
   
    lbl = Str(acc)
End If
Joe Shmoe 33 Light Poster

Among several other things, you're not telling python to do with that file your opening, you're not going to like the output, how about open(file,'r')...

But isn't r the default option? Meaning if you don't type anything it will use r. The opening of files is not the issue here. Can anyone help with the sorting? Thanks.

Joe Shmoe 33 Light Poster

No. I was having a brain cramp. It is meant to sort whole words.

Joe Shmoe 33 Light Poster

I wrote the following code in Python. It does not sort the list. Can anyone help me out?

theList = []

def simpleSort():
    pos = 1
    comps = 0
    while pos < len(theList):
        comps += 1
        if ord(theList[pos]) >= ord(theList[pos - 1]):
            pos += 1
        else:
            temp = theList[pos]
            print(theList[pos])
            theList[pos] = theList[pos - 1]
            print(theList[pos])
            theList[pos - 1] = temp
            if pos == 1:
                pos += 1
            else:
                pos -= 1
    return comps


def main():
    fileName = input("Type a filename: ")
    aFile = open(fileName)
    for line in aFile:
        theList = line.split()
        print("Original List:")
        print(theList)
        comps = simpleSort()
        print("Sorted List:")
        print(theList)
        print("Compares:")
        print(comps)
        

main()
Joe Shmoe 33 Light Poster

How are you parsing expressions like (1 + 2 * (3 + 4))? How are you representing them? How are you handling control structures within control structures? I'm going to guess this language interpreter is incredibly simplistic.

It's pretty simplistic. Control structures within control structures are handled by just using a stack. No, it does not parse expressions like that. I could implement that, but didn't take the time. I wrote it a few years back, so there are many things about it that I could improve.

Here is a simple nested loop example in my language:

define:value i
define:value j

->while [value] i < 10
	+ i
	out I is = [value] i [newline] $
	->while [value] j < 3
		+ j
		out J is = [value] j [newline] $
		->repeat 2
			out major test [newline] $
		<-
	<-
	->repeat 2
		out yay [newline] $
	<-
	setvalue j 0
<-

AnyKey Press any key to get out. . . $

I started "programming" when I spent my time inventing sorting algorithms on a deck of cards for fun before I entered kindergarten.

I have trouble believing that.


The example you made does seem simpler than the iterative way. Would doing it this way effect the speed at all or do you think it would execute the same speed both ways?

Joe Shmoe 33 Light Poster

I would say SDL is the way to go if you want to use C/C++/C#. It's super easy to pick up and use and can be used as a base for 3D OpenGL stuff later on, if you so choose.

There are lots of viable alternatives out there, I just happen to be really into SDL at the moment.

+ 1

Joe Shmoe 33 Light Poster

.NET is not a language. WTF are you talking about?

I know. I thought you would understand that I meant languages based on the common language run-time (CLR) which is .NET.

Joe Shmoe 33 Light Poster

Rashakil, how did you learn how to program? Did you start off by taking a class or did you teach yourself in an unofficial manner? I taught myself since I was 10 years old and I think that's probably why there's a difference in the ways we would approach the problem. It's probably because when I taught myself, I always used for loops and have become used to using them. For you, I am guessing you learned recursion fairly early on, and then therefore find it easier to think about problems that way.

I don't see why there's a problem doing it non-recursively if it is easier for me doing it that way.

Joe Shmoe 33 Light Poster

A simple for loop won't do the trick. Go ahead and try converting the program below to a simple for loop. You'd have to manually implement a stack of state variables. A recursive implementation expresses the behavior in a much more straightforward manner, because you can follow the behavior of the function in a straightforward manner.

That's funny because someone else told me that too, but I actually found it was easier doing it using for loops. I did it both ways. I don't understand how that is a more straightforward manner. It makes you have to think about how it's going to unwind after the recursion is done. With a for loop, the thinking is very linear.

Your biggest problem right now is that since you're ignorant of new ideas, you can't use them, and therefore they're not useful to you, and if they're not useful, why bother learning them? Do you see the fallacy here? There is no reason to bitch about being taught recursion unless you're actually bad at it, in which case you need to man up and practice it.

I just wrote that program, so yes, I can use recursion. I am just saying that it is easier for me and for the computer to use for loops instead of recursion. Why fill up the stack?

parsing a language

I have written my own language interpreter, and never used recursion.


Here is the loop version. It's in a different language …

Joe Shmoe 33 Light Poster

I had to write a triply nested recursive algorithm to draw squares on the screen. Your probably thinking how hard could it possibly be to just draw squares on the screen? Well look at the code below. Anyway, I don't understand why CS teachers emphasize recursion so much. In my opinion it just over complicates the problem. I also don't like the idea of pushing so much data onto the stack when a simple for loop will do the trick. All of my CS teachers (had three so far) taught recursion even before talking about loops. Just think about how little recursion is used in the average everyday program. Almost never. Loops are used in pretty much every program, yet the teachers think they are being so clever because they did it Recursively. It's the same thing with calculus - Do you ever use it in real life? No. But for some reason, these people feel the need to teach meaningless (well not meaningless, but you know what I mean) overly complex things.

Sorry for the rant. I hope you guys would agree.

Here is the program anyway. It's horribly constructed because I had to do it recursively. It's python btw.

from turtle import *

ifEven = 0

"""
This function will setup the window and turtle
pre: turtle is included
post: screen setup
"""
def init():
    setup(600, 600)
    speed('fastest')
    home()
    left(180)

"""
This is 3/4 square drawing function
pre: the depth and size have been inputed …
Joe Shmoe 33 Light Poster

@mustafaneguib: I understand that the need for a new language is minimal at this point because there is pretty much a language for every need. It would be nice though, in my opinion, if there was a language like .NET that compiled to native code for faster execution. Anyway, I don't design programming languages for a certain purpose, I just do it because I like designing programming languages (and like to brag about something most people wouldn't understand).

Joe Shmoe 33 Light Poster

Wow this is really weird. I can even name the file Xyz1, but not Adv1. I am really confused as to why it doesn't work with Adv in the name. Anyone know?

Joe Shmoe 33 Light Poster

YESSSSSSSSSSSSSSSSSSSSSSSSSS! I F***** DID IT!!!!

It's the f***** name. I just renamed the file AdvOne instead of Adv1 and it works. WOW! If that's a bug in firefox, then I am going to kill them.

Joe Shmoe 33 Light Poster

I am having a problem with flash in firefox 7. I am not sure this is the right forum, but someone can move it if they see fit. Anyway, say I write some embed code like this:

<html>
    <body>
     
    <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     
    codebase="http://download.macromedia.com/pub/shockwave/
    cabs/flash/swflash.cab#version=6,0,40,0"
     
    width="800" height="600"
    id="mymoviename">
     
    <param name="movie"
     
    value="Adv1.swf" />
     
    <param name="quality" value="high" />
     
    <param name="bgcolor" value="#ffffff" />
     
    <embed src="Adv1.swf" quality="high" bgcolor="#ffffff"
     
    width="800" height="600"
     
    name="mymoviename" align="" type="application/x-shockwave-flash"
     
    pluginspage="http://www.macromedia.com/go/getflashplayer">
     
     
    </embed>
    </object>
    </body>
    </html>

If I have a folder with this file and a file Adv1.swf, when I open the html in firefox, the flash shows. However, when these two files (index.html and Adv1.swf) are uploaded to a server, it does not work in firefox, but does in opera and IE. Please help me. I have been looking for a solution for about 8 hours.

Joe Shmoe 33 Light Poster

Ok. Why not. I'm bored. Here is a little more detail.

Here is some pseudo code of what a very simple interpreter might be like.

open a text file
store the text file into a string
replace all newline and caridge return characters with a space
now split that string by every space and store to an array
now make two functions. name one forward and one backward
the forward function reads the next command from the array and the
backward obvious
now make a giant switch statement to process the commands
now add your commands to the switch statement

That's the basic idea behind my language. Is it the best way to do it, maybe not, but it works and is very fast. Another pointer when designing an interpreter is DON'T make an interpreter using an interpreter. Use native code, like C or something. This will make your language a lot faster and less bloated.

Joe Shmoe 33 Light Poster

The best way to start making a programming language is by learning a current language as much as you can. Then begin by making an interpreter. Making a compiler requires a lot of knowledge of machine code etc., but with an interpreter you can pretty much make your own machine code (called byte code) or just have it interpret on the fly. Making an interpreter is actually nowhere near as hard as making a compiler. For making an interpreter, as long as your a good programmer, you don't really need to know any techniques. I mean, it's better if you do, but it doesn't matter. I am working on my own language interpreter right now and yes, you have to be willing to spend a lot of time. But in terms of brain power required, not much.

Before you actually program anything, start out by mapping out what you want the language to be like. Then take programs from other languages and convert them to yours. This will help you find areas that you forgot to implement. After you've converted a lot of programs and found that your language is complete enough to meet your needs, then start designing the visual part. I would recommend making the visual part of the language completely separate from the actual code. What I mean is, don't try to interpret the graphics, just have the graphics represent certain code. If you are just interested in the graphical part of the language, then you …

Joe Shmoe 33 Light Poster

Can anybody give the list of environment variable functions list.

There's only one environment variable function on windows and that is getenv(). FYI: When entering the environment variable, it is entered like getenv("TMP") not getenv("%TMP%").

Did you mean you wanted the list of variables?
http://libertyboy.free.fr/computing/reference/envariables/index.php

Joe Shmoe 33 Light Poster

You will probably need to open the file in a hex editor and look at the first 2 to 3 bytes to figure out the file type or maybe you can just open it in a text editor. After that, you can google those characters to find out the file type and extension.

Joe Shmoe 33 Light Poster

write a simple vb exe written in notepad

Impossible. You need to install VB6 to make exes. Install it. Then do what AndreRet said.

Joe Shmoe 33 Light Poster

Cause I have lost my working project as a result of formating my PC

Sorry, but that will be "hacking" someone else's code.

It's his code!

You can try this tool: http://www.soft32.com/download_124248.html

Or just google vb6 exe decompiler. You won't be able to get the code back exactly as you typed it, but if you know a little assembler it will help you remember what you coded.

Joe Shmoe 33 Light Poster

Lines:
# 23-35
# 46-62
# 131-158

Can you explain how these sections work and how I can implement something similar. Also tell me if I need any other parts of this code to make the switch work the way it does.

Joe Shmoe 33 Light Poster

Ok. The only reason I didn't is because it is really long.

Here's the code:

/* A tiny BASIC interpreter */

#include "stdio.h"
#include "setjmp.h"
#include "math.h"
#include "ctype.h"
#include "stdlib.h"

#define NUM_LAB 100
#define LAB_LEN 10 
#define FOR_NEST 25
#define SUB_NEST 25
#define PROG_SIZE 10000

#define DELIMITER  1
#define VARIABLE  2
#define NUMBER    3
#define COMMAND   4
#define STRING	  5
#define QUOTE	  6

#define PRINT 1
#define INPUT 2
#define IF    3
#define THEN  4
#define FOR   5
#define NEXT  6
#define TO    7
#define GOTO  8
#define EOL   9
#define FINISHED  10
#define GOSUB 11
#define RETURN 12
#define END 13

char *prog;  /* holds expression to be analyzed */
jmp_buf e_buf; /* hold environment for longjmp() */

int variables[26]= {    /* 26 user variables,  A-Z */
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0
};

struct commands { /* keyword lookup table */
  char command[20];
  char tok;
} table[] = { /* Commands must be entered lowercase */
  "print", PRINT, /* in this table. */
  "input", INPUT,
  "if", IF,
  "then", THEN,
  "goto", GOTO,
  "for", FOR,
  "next", NEXT,
  "to", TO,
  "gosub", GOSUB,
  "return", RETURN,
  "end", END,
  "", END  /* mark end of table */
};

char token[80];
char token_type, tok;

struct label {
  char name[LAB_LEN];
  char *p;  /* points to place to go in source file*/
};
struct label label_table[NUM_LAB];

char *find_label(), *gpop();

struct for_stack {
  int var; …
Joe Shmoe 33 Light Poster

I was looking at the following site because I am interested in making a basic-like interpreter in c. Can someone explain how the switch case works in this particular program? You probably need to read the code to know what I mean. I know how to use switch case, just not in the way they did.

Here is the site:

http://www.programmersheaven.com/download/16060/download.aspx

Joe Shmoe 33 Light Poster

I am a VB programmer, so I know a lot about programming. I am just new to C and want to ask a simple question.

How can I read a file and use strtok with space as the delimiter and have access to all tokens in memory? The example provided at cplusplus.com is not exactly what I need. The thread, http://www.daniweb.com/forums/thread55584.html, on this site is also not exactly it.

The problem in the examples provided is that the char array is overwritten each time a new token is read. I need to be able to access all of the tokens from memory.

In VB I would code something like this:

Dim strline As String
Dim strall As String
Dim arrtok() As String

Open "B:\test.txt" For Input As #1
Line Input #1, strall
Do While Not EOF(1)
    Line Input #1, strline
    strall = strall & " " & strline
Loop
Close #1

arrtok() = Split(strall, " ")

MsgBox arrtok(0), vbInformation, "This is token 1"
MsgBox arrtok(1), vbInformation, "This is token 2"
MsgBox arrtok(2), vbInformation, "This is token 3"

How can I do the same in C? I'd like to use char arrays for this, not c strings if possible.

Joe Shmoe 33 Light Poster

Through each for loop (on line 52), the variable fullpath has to be reset to the temporary directory. On another forum, someone said that it was not working because it was a pointer. So my question is why won't fullpath = temp?

what do you really have to do?

I am making a files extractor program.

Joe Shmoe 33 Light Poster

The line fullpath = temp; doesn't actually reset the var. I am not sure what I have to do. I have tried fullpath = *temp;. Could someone tell me why this is not working?

#include "stdio.h"
#include "stdlib.h" //Used for getenv();
#include "string.h" //Used for strcat();

int main(int argc, char* argv[])
{
    //Make vars
    FILE *self;
    FILE *ext;
    int lengthof;
    int sum;
    int fatpos;
    int i;
    int fcount;
    char filename[32];
    char *filedata;
    char *temp;
    char *fullpath;
    const int F_SIZE = 6144; //Size of this program (the stub)

    //Open self, set pointer to the end of the stub
    self = fopen(argv[0], "rb");
   	fseek(self, F_SIZE, SEEK_SET);

	//Read integer for number of files in archive
    fread(&fcount, sizeof(int), 1, self);
    
    //Figure out how long the FAT is
    sum = ((32 + sizeof(int)) * fcount) + sizeof(int);
    
    //Set up the position saver thing (used to keep the position in the FAT so program can seek back after file is read)
    fatpos = F_SIZE + sizeof(int);
    
    //Get the location of the temporary directory
    temp = getenv("TEMP");
    if(strlen(temp) > 3)
    {
         strcat(temp, "\\");
    }

	//Loop through the file names
	for(i = 0; i < fcount; i++)
	{
          fread(filename, 32, 1, self);                //Read the file name of 32 bytes max (will auto terminate at zero byte)
          fatpos += 32;                                //Add 32 to the position
          fread(&lengthof, sizeof(int), 1, self);      //Get length of file
          fatpos += sizeof(int);                       //Add a long to the position
          fseek(self, F_SIZE + sum, SEEK_SET);         //Go to the file
          sum += lengthof;                             //Add to the length …
Joe Shmoe 33 Light Poster

You're declaring a variable-length array here. It's not standard C89 to do that. If I were you I'd just declare the array as

Do you mean that I should just make a const called MAX_FCOUNT. If so, what should I set it to?

All that seeking is unnecessary. The filenames are all contiguous in the file, so just read the first, then the second, and so on. After reading one filename, your file pointer will already be in the correct position to read the next.

I didn't know that. I'll correct it.

How are you generating this executable? Because you'll have to add some stuff onto the end to make it work.

For now, I am just going to use copy /b exefile.exe + data.bin + otherstuff.bin archive.exe. That will copy all of the files together. Later on I might make another program to generate it, but I don't need to. Yes, all of the files will be added to the end of the exe.

I should mention that in doing so, you may mess up the executable format.

No, you can add data to the end of an exe without messing it up.

Joe Shmoe 33 Light Poster

I am trying to make a file extraction program in C and I can't get it to work. It compiles ok, but it has a run-time error. I hope you can figure out what I am trying to do here. I don't know if there is a standard way to do this. I am going to make a table with length of files later. Is there a way to determine EOF without having a table of lengths?

Here is the layout of the file:
1. extraction program
2. 4 bytes for number of files in archive
3. table of files (each 16 bytes long)
4. length of each files in table (not implemented)

#include "stdio.h"

int main(int argc, char* argv[])
{
    //Declair vars
    FILE *self;
    int fcount = 0;
    int i;
    //Size of this program (the stub)
    const int F_SIZE = 6143;
    
    //Open self, set pointer to the end of the stub
    self = fopen(argv[0], "rb");
   	fseek(self, F_SIZE, SEEK_SET);
	
	//Read integer for number of files in archive
    fread(&fcount, 4, 1, self);
    char filenames[fcount][16];
	
	//Loop through the file names
	for(i = F_SIZE + 4; i < F_SIZE + 4 + (fcount * 16); i+=16)
	{
          fseek(self, i, SEEK_SET);
          fread(&filenames[i][16], 16, 1, self);
 }
	fclose(self);
	
	for(i = 0; i < fcount; i++)
	{
          self = fopen(&filenames[i][16], "w");
//This part is just to test if it can make the files
          fprintf(self, "%c", 144);
          fclose(self);
}
	
    return 0;
}
Joe Shmoe 33 Light Poster

I figured it out!!!!!!! :)

I had the track set to one and the second sector is on track zero.
So I changed this

mov	ch, 01	;Track to read

to this

mov	ch, 00	;Track to read

And I added this before the jmp 0x1000:0x0000

mov ax, 0x1000
mov ds, ax
Salem commented: Congrats, and thanks for the feedback of your solution. +33
Joe Shmoe 33 Light Poster

If there is nothing wrong with what I did above, then how should the next sector start?

Here is the beginning of the second sector. Is there something wrong with this or is there something I need to add?

use16
org 0x10000
jmp main

main:
Joe Shmoe 33 Light Poster

I am just starting to learn x86 assembly language because eventually I want to make my own OS. I wrote a boot sector in fasm and it doesn't load the second sector into memory. Because I just started, there is probably something obvious wrong with the code. Could anyone tell me what I am doing wrong? Could the problem be in the second sector?

use16
org 0x7C00

start:
	jmp	bootit

;**********************************************************;
;*	OEM Parameter block / BIOS Parameter Block        *;
;**********************************************************;

TIMES 0Bh-$+start DB 0

bpbBytesPerSector:  	DW 512
bpbSectorsPerCluster: 	DB 1
bpbReservedSectors: 	DW 1
bpbNumberOfFATs: 	DB 2
bpbRootEntries: 	DW 224
bpbTotalSectors: 	DW 2880
bpbMedia: 	        DB 0xF0
bpbSectorsPerFAT: 	DW 9
bpbSectorsPerTrack: 	DW 18
bpbHeadsPerCylinder: 	DW 2
bpbHiddenSectors:       DD 0
bpbTotalSectorsBig:     DD 0
bsDriveNumber: 	        DB 0
bsUnused: 	        DB 0
bsExtBootSignature: 	DB 0x29
bsSerialNumber:	        DD 0xa0a1a2a3
bsVolumeLabel: 	        DB "BOS FLOPPY "
bsFileSystem: 	        DB "FAT12   "

;----------------------------------------;
;   starting point of bootsector code    ;
;----------------------------------------;
bootit:
	cli

	xor	ax, ax
	mov	ds, ax
	mov	es, ax
	mov	ss, ax
	mov	sp, 0xFFFF

	sti
	mov	cx, 5		;we are going to loop 5 times

mainloop:
	mov	si, msgloading
	call	print		;print the string
	call	crlf		;new line
	loop	mainloop	;loop 5 times because cx decreased each time

	mov	si, msgnext
	call	print
	mov	ah, 0		;procedure to call inside keypress int
	int	0x16		;keypress int

	mov	ax, 0x1000	;read sector to address 0x1000:0
	mov	es, ax
	xor	bx, bx	;Offset to read into (zero because it is cleared)
	mov	ah, 02	;BIOS read sector function …