Results 1 to 12 of 12
  1. #1
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty

    Home Stretch! :)

    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

  2. #2
    Obama's Avatar
    Join Date
    Dec 2008
    Gender
    male
    Location
    The Black house
    Posts
    22,195
    Reputation
    870
    Thanks
    6,076
    My Mood
    Cool
    You need to learn how to make hacks bish.

  3. #3
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    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

  4. #4
    Obama's Avatar
    Join Date
    Dec 2008
    Gender
    male
    Location
    The Black house
    Posts
    22,195
    Reputation
    870
    Thanks
    6,076
    My Mood
    Cool
    Quote Originally Posted by why06 View Post
    Damn that was quick... and that is what I'm doing... =/

    You can't rush Obama.

    Maybe three more months if I'm good... :l
    Yeah I feel you

  5. #5
    wtfiwantthatname's Avatar
    Join Date
    Oct 2008
    Gender
    male
    Posts
    260
    Reputation
    10
    Thanks
    39
    My Mood
    Bored
    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.

  6. #6
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    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

  7. #7
    Void's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Location
    Inline.
    Posts
    3,198
    Reputation
    205
    Thanks
    1,445
    My Mood
    Mellow
    Not sure exactly what you're trying to do, but shouldn't you replace:
    Code:
    for(int i = 0; temp[i];i++)
    with:

    Code:
    for(int i = 0; i < strlen(str); i++)
    I don't get how what you wrote works.

  8. #8
    wtfiwantthatname's Avatar
    Join Date
    Oct 2008
    Gender
    male
    Posts
    260
    Reputation
    10
    Thanks
    39
    My Mood
    Bored
    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

  9. #9
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    Quote Originally Posted by wtfiwantthatname View Post
    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].
    Thanks, but I tried that before. I get this error:
    Code:
    52 C:\Dev-Cpp\My Projects\WordLinker.cpp invalid type argument of `unary *'
    I've also tried char links[5000]; =/

    "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

  10. #10
    Matrix_NEO006's Avatar
    Join Date
    Feb 2008
    Gender
    male
    Posts
    240
    Reputation
    12
    Thanks
    33
    My Mood
    Lonely
    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

  11. #11
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    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

  12. The Following User Says Thank You to why06 For This Useful Post:

    Void (11-18-2009)

  13. #12
    Jimmy's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    Jersey
    Posts
    4,572
    Reputation
    70
    Thanks
    647
    2 more monthes

Similar Threads

  1. Going home alone tonight?
    By tednugent in forum Art & Graphic Design
    Replies: 12
    Last Post: 08-08-2007, 01:09 AM
  2. Windows Vista Home Premium Lite
    By djtwistter01 in forum Hardware & Software Support
    Replies: 0
    Last Post: 07-09-2007, 01:24 AM
  3. Benoit family found dead in their home
    By ace76543 in forum General
    Replies: 40
    Last Post: 06-29-2007, 01:06 AM
  4. THREAD: Home Made Explosives!
    By SadisticGrin in forum General
    Replies: 10
    Last Post: 10-25-2006, 03:15 PM

Tags for this Thread