Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 09-24-2003, 01:44 PM   #1 (permalink)
saline
I am red.
 
saline's Avatar
 
Join Date: Feb 2003
Location: Cleveland, OH
Posts: 139
saline is on a distinguished road
A day late and pointers short

I'm having trouble kids... systems programming is kicking my ass and I've returned from a long hiatus at work for help.

Code:
#include <iostream>
#include <string>
#include "Item.h"

using namespace std;

template < class AT >
struct NODE{
	Item<AT> * attrib;
	NODE<AT> * next;
};

template< class AT >
class SymTab {

	public:
		SymTab(); // Initializes the empty table, a vector of 157 linked list heads.		
		Item< AT > * find( string s ); // Returns Item pointer or NULL
		Item< AT > * insert( string s ); // Returns Item pointer to inserted string

	private:
		int hash( string s ); // Returns bucket hashed to (0 <= return value <= 156)				
		NODE<AT> *Table[157];

};

//constructor
template < class AT >
SymTab< AT >::SymTab()
{
for(i=0; i < 157
}


//find, locates items in the table and returns pointers to them or null
template < class AT >
Item<AT>* SymTab< AT >::find( string s )
{
int value, i=0, Fspace = 0, Lspace = 0;
string OpCode, Hex;
char Sic;
Item<AT> * ItemPtr;

//Splits up the string into OpCode, Hex value and S or X for Sic or Sic/XE
Fspace = s.find(' ');
Lspace = s.rfind(' ');
cout << "First: " << Fspace << endl;
cout << "Last: " << Fspace << endl;

OpCode = s.substr(0, Fspace);
Hex = s.substr(Fspace+1, 2);
Sic = s[s.length()-1];
//Done splitting

value = hash(OpCode);

if(Table[value]->next->item->name == s)
ItemPtr = SymTab[value];

return ItemPtr;
}

//insert, puts items into the table.
template < class AT >
Item<AT>* SymTab<AT>::insert( string s )
{
int value, i=0, Fspace = 0, Lspace = 0;
string OpCode, Hex;
char Sic;
Item<AT> * ItemPtr;

//Splits up the string into OpCode, Hex value and S or X for Sic or Sic/XE
Fspace = s.find(' ');
Lspace = s.rfind(' ');
cout << "First: " << Fspace << endl;
cout << "Last: " << Fspace << endl;

OpCode = s.substr(0, Fspace);
Hex = s.substr(Fspace+1, 2);
Sic = s[s.length()-1];
//Done splitting

value = hash(OpCode);  // Gets the hash value from the OpCode

ItemPtr = new Item<AT>(OpCode);
cout << "a" << endl;

Table[value]->attrib = ItemPtr;

cout << &Table[value]->attrib  << endl;//= ItemPtr;

cout << "a" << endl;

//if(the SymTab[value] is occupied && it's not occupied by the same value)
//{
//set flag to different
//}
//else (SymTab[value] is not occupied)
//Set ItemPtr and point SymTab[value]'s pointer to it.

return ItemPtr;
}

template < class AT >
int SymTab<AT>::hash(string s)
{
int hash_value=0, i=0, int_cast=0, size = 10;
int Poly[10];

for(i=0; i < size; i++)
{
	int_cast = int(s[i]);
	Poly[i] = int_cast;
}

for(i=0; i < s.length(); i++)
{
hash_value += (s[i] * 256);
}
hash_value %= 157;
cout << "hash_value: " << hash_value << endl;

return hash_value;
}
My issue is that the bold line just ain't cutting it. For some reason the pointers just aren't assigning properly.
__________________
http://home.cwru.edu/~cak19

It's my homepage with odd little bits of javascript.
saline is offline   Reply With Quote
Old 09-26-2003, 06:24 AM   #2 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
Weekend... got time. Please give item.cpp and item.h if you will. Or pm it to me if relevant.
__________________
Valmont is offline   Reply With Quote
Old 10-04-2003, 10:33 AM   #3 (permalink)
saline
I am red.
 
saline's Avatar
 
Join Date: Feb 2003
Location: Cleveland, OH
Posts: 139
saline is on a distinguished road
got it

Well, for the most part I got it. Sorry I didn't post the rest of it but I actually ended up changing large parts of the program and I'm glad I got it more or less myself. Thanks for your help I'm sure I'll need it again soon.
__________________
http://home.cwru.edu/~cak19

It's my homepage with odd little bits of javascript.
saline is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 11:36 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting