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

    I need serious help

    Ok. I simplified the code down a lot to something manageable. Here's the problem. You see this code posted below? Well pretend the array char* p[50] contains three strings. the first element in the array is "ho" the second is "ha" and the last one is "he"

    Now when I first print p[1] (the second element in the array) it prints "ha" and only "ha", but when I print p[1] for the second time it prints "ha he" (both the second and third element. Does anyone know why this is?

    if you have to assume the variable word is an integer that starts off at the value 3

    [php]
    cout<<"p[1] " << p[1];
    while(words > 0)
    {
    strcpy(init_str, str);
    temp = strtok(init_str, " \"");
    while(temp != NULL)
    {
    if(!strcmp(p[words-1], temp))
    {
    cout<<"eliminating redundancy";
    temp = strtok(NULL," \"");
    continue;
    }
    cout<<p[1];
    temp = strtok(NULL," \"");
    }
    words--;
    }
    [/php]

    Thanks in advance everyone. I could really use some help on this. Been scratching my head trying to figure this mess out for weeks, and I finally get it to the point where it should work, except its screwing up, because of this....
    Last edited by why06; 11-16-2009 at 12:03 AM.

    "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
    zeco's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    Canada
    Posts
    683
    Reputation
    12
    Thanks
    78
    My Mood
    Cynical
    Why does the array of 50 strings only contain 3? And i'm assuming you mean the first 3 contain strings.

    (more to come maybe)

  3. #3
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,204
    My Mood
    Flirty
    Quote Originally Posted by zeco View Post
    Why does the array of 50 strings only contain 3? And i'm assuming you mean the first 3 contain strings.

    (more to come maybe)
    To handle overflow, but the outside significance of this code isn't importance, in fact if I explained more it would simply overcomplicate things.

    And yes ofcourse the first three elements

    "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
    Matrix_NEO006's Avatar
    Join Date
    Feb 2008
    Gender
    male
    Posts
    240
    Reputation
    12
    Thanks
    33
    My Mood
    Lonely
    p[0] = 1st element , p[1] = second element and p[2] = 3rd element.

  5. #5
    zeco's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    Canada
    Posts
    683
    Reputation
    12
    Thanks
    78
    My Mood
    Cynical
    Quote Originally Posted by Matrix_NEO006 View Post
    p[0] = 1st element , p[1] = second element and p[2] = 3rd element.
    No comment at the above.

    Eitherway, The strings in the array aren't being changed at all, so maybe its how it's being displayed, But that doesn't make sense either.

  6. #6
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,204
    My Mood
    Flirty
    Yes, but the important thing to realize is this:

    p[1] at first = "ha"
    then the second time I call p[1]
    p[1] = "ha he"

    if you don't believe me try this yourself... and giving stand in values for the variables.

    "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
    zeco's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    Canada
    Posts
    683
    Reputation
    12
    Thanks
    78
    My Mood
    Cynical
    Quote Originally Posted by why06 View Post
    Yes, but the important thing to realize is this:

    p[1] at first = "ha"
    then the second time I call p[1]
    p[1] = "ha he"

    if you don't believe me try this yourself... and giving stand in values for the variables.
    Yeah i understand that... I'm trying to figured it out right now too... But looking at your code makes me sleepy. And i was about to elaborate on my above post....

  8. #8
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,204
    My Mood
    Flirty
    I'm tired too... yawn... it probably has something to do with strcpy() oh well I'll look into it tomorrow when I can focus >_>....

    "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

  9. #9
    zeco's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    Canada
    Posts
    683
    Reputation
    12
    Thanks
    78
    My Mood
    Cynical
    -.- Why06, i hate you. Because of your program i realized I forgot some of how multi-level pointers worked....and ended up spending half an hour going crazy to reteach myself. It's all good now though.

    Anyway the only thing i can think of is if somehow the null character between p[1] and p[2] dissappeared
    Last edited by zeco; 11-16-2009 at 01:05 AM.

  10. #10
    BMW M5's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Location
    U.S.A
    Posts
    1,161
    Reputation
    14
    Thanks
    196
    My Mood
    Aggressive
    Is it possible that first time it works but maybe cuz of coding the second time it adds on to first and reads as p2?

  11. #11
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,204
    My Mood
    Flirty
    Quote Originally Posted by zeco View Post
    -.- Why06, i hate you. Because of your program i realized I forgot some of how multi-level pointers worked....and ended up spending half an hour going crazy to reteach myself. It's all good now though.

    Anyway the only thing i can think of is if somehow the null character between p[1] and p[2] disappeared
    possibly, I'll have to look into that... lol sorry I kept you up... I'm sort of like that too, once I get working on something its hard for me to stop. until I figure it out...

    Quote Originally Posted by bmw
    Is it possible that first time it works but maybe cuz of coding the second time it adds on to first and reads as p2?
    It's more then possible. That's what the problem is, but thanks for generalizing it down like that.






    Here see I simplified it even more... so it definitely has something to do with the strcpy() and strtok() functions...
    [php]
    cout<<"p[1] " << p[1]; // this will print "he"
    while(words > 0)
    {
    strcpy(init_str, str);
    temp = strtok(init_str, " \"");
    cout<< p[1]; //this will print "ha he"
    }

    //Assume the following conditions before the code executes:
    //temp, init_str, and str are all char*
    //temp = "";
    //init_str = "";
    //str = "ho ha he";
    //p[0] = "ho"; p[1] = "ha"; p[3] = "he"
    [/php]
    Last edited by why06; 11-16-2009 at 08:18 AM.

    "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. #12
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,204
    My Mood
    Flirty
    Ok. Maybe I simplified it a little too much this has grown far more complicated then I initially suspected. Now I'm of the suspension that it is p[1]'s link to init_str that is causing the problem. I will demonstrate
    [php]
    char* p[50];
    int words = 0;
    char* init_str;
    strcpy(init_str, str);

    char* temp = strtok(init_str, " \"");
    while(temp != NULL)
    {
    p[words] = temp;
    temp = strtok(NULL, " \"");
    words++;
    }
    cout<<"p[1] " << p[1] <<endl;
    while(words > 0)
    {
    strcpy(init_str, str);
    char* temp2 = strtok(init_str, " \"");//Here I declared a completely new temporary string, just to test weather temp was the problem.
    cout<<p[1]<<endl; // Its not. It has something to do with p[1] connection to init_str through temp...
    }
    [/php]

    Im so screwed....
    Last edited by why06; 11-16-2009 at 09:15 AM.

    "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

  13. #13
    BMW M5's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Location
    U.S.A
    Posts
    1,161
    Reputation
    14
    Thanks
    196
    My Mood
    Aggressive
    Try erase the second "str" in the strcpy line

  14. #14
    lalakijilp's Avatar
    Join Date
    Jan 2008
    Gender
    male
    Posts
    310
    Reputation
    9
    Thanks
    53
    My Mood
    Blah
    maybe this is the problem...

    i think it isn't but you can try it.
    the end of the string is a zero i think that is a delimiter to but there is a possibility it isn't

    To determine the beginning and the end of a token, the function first scans from the starting location for the first character not contained in delimiters (which becomes the beginning of the token). And then scans starting from this beginning of the token for the first character contained in delimiters, which becomes the end of the token.

    source: strtok - C++ Reference
    you string ends with a not delimiter so the third piece of string never was gotten out of the original string.

  15. #15
    zhaoyun333's Avatar
    Join Date
    Apr 2009
    Gender
    male
    Posts
    396
    Reputation
    11
    Thanks
    1,125
    How about you dont use a pointer of character arrays
    There are five possible operations for any army. If you can fight, fight; if you cannot fight, defend; if you cannot defend, flee; if you cannot flee, surrender; if you cannot surrender, die." - Sima Yi

Page 1 of 2 12 LastLast

Similar Threads

  1. [Help Request] I NEED SOME SERIOUS HELP. PLEASE.
    By GoGrandma in forum Combat Arms Help
    Replies: 4
    Last Post: 07-19-2011, 10:07 AM
  2. [Help Request] need serious help guys
    By pyrozombie in forum Call of Duty Modern Warfare 2 GSC Modding Help/Discussion
    Replies: 7
    Last Post: 06-09-2011, 10:29 AM
  3. [Help] Need serious help about the dinar bot!
    By ramiwr00 in forum WarRock Hack Source Code
    Replies: 4
    Last Post: 02-02-2011, 10:37 AM
  4. I NEED SERIOUS HELP
    By quake420 in forum Combat Arms Mod Discussion
    Replies: 2
    Last Post: 12-07-2010, 12:20 AM
  5. yo i need serious help plz help
    By josephjboogie3 in forum Visual Basic Programming
    Replies: 4
    Last Post: 11-18-2007, 12:38 PM

Tags for this Thread