You need to learn how to make hacks bish.
I'm nearly finished working out all the bugs out of my WordLinker. There is just one problem left.
[php]
void addDirLink(char* str)
{
char temp[50] = "";
strcpy(temp, str);
for(int i = 0; temp[i]; i++)
{
linkcount++;
//here is the problem
//Somehow its passing a pointer to temp[i]
//rather then the value....
//I already have memory allocated all I need is the value... not a pointer
links[linkcount] = temp[i];
}
linkcount++;
links[linkcount] = ' ';
}
char* getLinks()
{
cout<<"What is links? " << links[0] <<endl;
return links;
}
[/php]
Some how link[linkcount] is being passed a pointer to temp[i] when what I want is the value to be stored in memory that won't disappear...
I might be able to figure it out myself.... =/
"Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."- Dwight D. Eisenhower
You need to learn how to make hacks bish.
Damn that was quick... and that is what I'm doing... =/
You can't rush perfection.
Maybe three more months if I'm good... :l
"Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."- Dwight D. Eisenhower
What was your declare for links? And how did you assign it its values? Did you pass by reference or value? We need to see some more code. Also if links[Linkcount] is being passed pointers to the values you need you can get those values using the pointer.
Sorry... that's the whole class:
[php]
class Word
{
int maxlinks;
char* wordname;
char* links;
int linkcount;
public:
Word(char str[]){strcpy(wordname, str);}
Word(){
maxlinks = 1000;
links = new char[maxlinks];
strcpy(links, "");
wordname = "";
linkcount = 0;
}
void newWord(char* str)
{
wordname =(char*)str;
}
char* getWord(){return wordname;}
void addDirLink(char* str)
{
char temp[50] = "";
strcpy(temp, str);
for(int i = 0; temp[i]; i++)
{
linkcount++;
//here is the problem
//Somehow its passing a pointer to temp[i]
//rather then the value....
//I already have memory allocated all I need is the value... not a pointer
links[linkcount] = temp[i];
}
linkcount++;
links[linkcount] = ' ';
}
char* getLinks()
{
cout<<"What is links? " << links[0] <<endl;
return links; //here getLinks returns nothing! D;
}
};
[/php]
"Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."- Dwight D. Eisenhower
Not sure exactly what you're trying to do, but shouldn't you replace:
with:Code:for(int i = 0; temp[i];i++)
I don't get how what you wrote works.Code:for(int i = 0; i < strlen(str); i++)
You declared Links as a pointer. So try *Links[linkcount] = temp[i]. And that should pass the value pointed to by the pointer links[linkcount].
"I don't believe in an afterlife, so I don't have to spend my whole life fearing hell, or fearing heaven even more. For whatever the tortures of hell, I think the boredom of heaven would be even worse." - Isaac Asimov
"Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."- Dwight D. Eisenhower
theres another way to dereference it but im not good at it so ill just demonstrate it.
Code:but before this you need to put the Word in pointer(I FORGOT HOW). Word->links
Haha finally figured it out... it seems so obvious now I look like an idiot. The problem was my incrementing of linkcount... I never overwrote the first char which was a NULL ... silly me :P Well now writing to the file is essentially out of the way. Now all I have to worry about is properly reading from it.
EDIT: btw... I was meaning to tell you this earlier David, but I was a little preocupied. my for loop simply checks to see whether temp has encountered a NULL char or that we reached the end of the string. It's shorthand for what you wrote.
Last edited by why06; 11-18-2009 at 06:58 PM.
"Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."- Dwight D. Eisenhower
Void (11-18-2009)