sigh... why dosent this work?

This is a discussion on sigh... why dosent this work? within the C++ Programming forums, part of the General Programming Boards category; After trying for 20 minutes with every possible way I could think of, I have come to seek expert advice ...

  1. #1
    Registered User jon_nc17's Avatar
    Join Date
    May 2002
    Posts
    15

    Question sigh... why dosent this work?

    After trying for 20 minutes with every possible way I could think of, I have come to seek expert advice lol....

    What I'm trying to do with the code below is have a array of 100 strings (lines[100]), and with this, I want to periodicly add a new string to it, and bump out the oldest array off. (ex. lines[0] becomes lines[1]... lines[100] gets bumped off) If we run out of room. So in order to do that, I've created two for () {... statements... the first one copies the array to a templines array.. then the next one trys to move all arrays up one, leaving lines[0] for me to put the new data in... and lines[100] gets deleted. Now, when I try to run the code below in my program, I get an error and Borland C++ 3.1 closes with an error. Am I doing somthing wrong? Or, how would you do this? I have declared the char *lines[100]; in the begenning of the program....

    // linecount = the current line the array is used up to

    if (lineCount >= 100) {

    char *templines[100];
    for (int i = 0; i <= 99; i++) {
    strcpy(templines[i], lines[i]);
    templines[i] = newStr( lines[i] );
    }

    for (int i = 0; i <= 99; i++) {
    strcpy(lines[i + 1],templines[i]);
    }
    strcpy(lines[0], "HI JON!\n");

    } else {
    lineCount++;
    strcpy(lines[lineCount], "HI JON!\n");
    }


    Thank you!
    Jon Scott

  2. #2
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,493
    After trying for 20 minutes with every possible way I could think of, I have come to seek expert advice lol....
    ... what are you saying about our expert skills? you doubt our judgement? a thousand firey birds with a thousand firey thunderbolts each attack your mother!

    seriously...
    i would suggest using the stl here. use vector classes. (and maybe string classes if you wish.
    vector classes have the built in ability to increment, insert, delete, etc...

  3. #3
    Registered User jon_nc17's Avatar
    Join Date
    May 2002
    Posts
    15

    lol.... I have no clue how to do that

    lol, well, thanks for the advice but I have no clue how to go about that... I'm not new to the programming scene, but to c++ I am ! lol, is there a example you could show me?

    Thanks for you help!

    Jon Scott

  4. #4
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    Jon, you sure do laugh out loud a lot.

    And, ygf, remind me never to get on your bad side...

    >>... what are you saying about our expert skills? you doubt our
    >>judgement? a thousand firey birds with a thousand firey
    >>thunderbolts each attack your mother

    Ouch! Poor mom!

    Jon, try this:

    Code:
    struct CharLines
    {
        char lines[100];
    };
    
    CharLines Lines[100];
    
    //initial variable population
    for(i=0;i<100;i++)
    {
       strcpy(Lines[i].lines,"hello");
    }
    
    if(lineCount>=100)
    {
        char newline[100], templine[100];
        strcpy(newline,"hi jon!");
        for(i=0;i<100;i++)
       {
           strcpy(templine,Lines[i].lines); //save current string
           strcpy(Lines[i].lines,newline);  //replace with new one
           strcpy(newline,templine);       //reset new one to former one
       }
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why this dosen't work in C
    By ruab in forum C++ Programming
    Replies: 9
    Last Post: 08-31-2006, 10:12 AM
  2. getline() don't want to work anymore...
    By mikahell in forum C++ Programming
    Replies: 7
    Last Post: 07-31-2006, 10:50 AM
  3. Why don't the tutorials on this site work on my computer?
    By jsrig88 in forum C++ Programming
    Replies: 3
    Last Post: 05-15-2006, 10:39 PM
  4. Problems in getting OpenGL to work
    By zonf in forum C Programming
    Replies: 5
    Last Post: 02-13-2006, 03:48 AM
  5. Why dosen't this work
    By Granger9 in forum C Programming
    Replies: 4
    Last Post: 08-16-2002, 08:18 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21