Thread: string help

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    23

    string help

    Hello all,

    I am taking a line of text (lineOfText) and trying to insert and email address at a specific location (locationFound). I make a copy of the line of text, add the email address and copy the remaininder of the string from the copy. when I run this, it prints the lineOfText up to where I inserted the email address and then stops....

    Code:
    void createNewGorseveRecord(char lineOfText[], int locationFound) 
    {
       int i;
       int fieldLength=0;
       int startPos=locationFound;
       int lineLength=0; 
       char *emailaddr = [email protected];
       char copyLine[LINESIZE];
       fieldLength = strlen(emailaddr);
       lineLength = strlen(lineOfText); 
       printf("NEW LINE: %s \n",lineOfText); 
       strcpy(copyLine, lineOfText); 
       for (i=0;i<=fieldLength;i++) 
       { 
         lineOfText[locationFound] = emailaddr[i]; 
         locationFound++; 
       } 
       for (i=startPos;i<lineLength;i++) 
       { 
           printf("< %d %c \n",i,copyLine[i]); 
           lineOfText[locationFound] = copyLine[i]; 
           printf("> %d %c \n",locationFound, lineOfText[locationFound]); 
           locationFound++; 
       } 
       printf("NEW LINE: %s \n",lineOfText);
    When I print out each character I am copying from and too, it shows the correct character, then when my last line prints the lineOfText, it truncates to where I enter the new string, is this a buffer size problem?
    Last edited by Dave_Sinkula; 08-03-2006 at 06:07 PM. Reason: Added [code][/code] tags -- learn to use them yourself.

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Code:
    for (i=0;i<=fieldLength;i++)
    Change the control field to i<fieldLength. e.g. from <= to <.

    The problem is you're copying the '\0' as well which is truncating the string. Changing the code that I just mentioned will fix it.
    If you understand what you're doing, you're not learning anything.

  3. #3
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    code tags.

  4. #4
    Registered User
    Join Date
    Aug 2006
    Posts
    23
    tytytytytytyty..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. compare structures
    By lazyme in forum C++ Programming
    Replies: 15
    Last Post: 05-28-2009, 02:40 AM
  2. OOP Question DB Access Wrapper Classes
    By digioz in forum C# Programming
    Replies: 2
    Last Post: 09-07-2008, 04:30 PM
  3. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM