SPONSORS:






User Tag List

Thanks Thanks:  0
Likes Likes:  0
Dislikes Dislikes:  0
Results 1 to 6 of 6

Thread: string clean up

  1. #1
    Senior Member
    Join Date
    Jan 2005
    Posts
    394
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    string clean up

    Hi,
    I have the below function.

    char buf1[50000]="\0",buf2[50000]="\0";
    char Body1[50000]="\0", Body2[50000]="\0";
    int ranNum;
    int g;
    SelectRandomSRA()
    { strcpy(buf1,"");
    strcpy(buf2,"");
    strcpy(Body1,"");
    strcpy(Body2,"");
    lr_output_message ("bufferclean %s",buf1);
    for(g=1;g<=192;g++)
    strcat(choose_SRAIncPro_buf,lr_eval_string("{List1 }"));
    strcat(buf1,",");
    strcat(buf2, lr_eval_string("{List2}"));
    strcat(buf2, ",");

    }

    strncat(Body1, buf1,strlen(buf1)-1);
    strncat(Body2, buf2,strlen(buf2)-1);
    lr_output_message("value of sra body =%s",SRBody1);
    lr_save_string(Body1,"List1"),
    lr_save_string(Body2,"List2");
    }

    But the issue here is the List1 and List2 gets growing as the iteration grows even after cleaning up the strings.

    strcpy(buf1,"");
    strcpy(buf2,"");
    strcpy(Body1,"");
    strcpy(Body2,"");

    Is there anything else i can do to clean them up?
    thx
    1. LR 9.5
    2. HTTP/HTML
    3. Yes
    4. - Concurrent groups,
    5. FP4
    6. New recording
    7. Permanent http/html 5000
    8. Permanent
    9. Windows-XP, SP2
    10. Not filed

  2. #2
    Moderator
    Join Date
    Jan 2006
    Location
    Charlotte, NC
    Posts
    1,600
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: string clean up

    First, you need to read and follow the posting instructions here:

    http://www.sqaforums.com/showflat.ph...e=0#Post117445

    Second, strcpy(mybuf, "") will work fine to initialize the string to empty. (mybuf[0] = '\0' does pretty much the same thing.)

    If List1&2 are growing as you don't want them to, then it means that there's a flaw in the logic you are using.
    Unless you are writing a compiler, strtok is NOT the answer.
    See: http://www.sqaforums.com/showflat.ph...=541641#542222

    QAF is still an exercise in self-sufficiency! (Thank JB!)

  3. #3
    Senior Member
    Join Date
    Apr 2009
    Location
    Canada
    Posts
    123
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: string clean up

    Hey,

    Even though i remember your profile, I would recommend you post your info everytime. Aside from giving pointers to what may be wrong with a particular script or question, it also serves as an example to newer people.

    That being said, Have you tried cleaning your strings with "\0" instead of ""?

    My understanding may be wrong but "" only replaces a character (or part of the string) and leaves the rest untouched while "\0" actually means the string has ended at position (in this case, the first char). Again this is speculation.

  4. #4
    Senior Member
    Join Date
    Jan 2005
    Posts
    394
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: string clean up

    thanks for the reply.

    I have listed the logic also.
    I dont see any flaw int he logic.

    all it does is select an item from the paramater list and append to the string for an iteration.

    Same process will be repeated for each iteration.

    thx
    1. LR 9.5
    2. HTTP/HTML
    3. Yes
    4. - Concurrent groups,
    5. FP4
    6. New recording
    7. Permanent http/html 5000
    8. Permanent
    9. Windows-XP, SP2
    10. Not filed

  5. #5
    Moderator
    Join Date
    Jan 2006
    Location
    Charlotte, NC
    Posts
    1,600
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: string clean up

    BL,

    "\0" is a more pedantic version of "". They're exactly the same as far as the compiler is concerned.

    ---------------------------------------

    Rose,

    "I dont see any flaw int he logic."

    Is it working correctly? If not, then SOMETHING is wrong! (Not intending to sound flippant.)
    Unless you are writing a compiler, strtok is NOT the answer.
    See: http://www.sqaforums.com/showflat.ph...=541641#542222

    QAF is still an exercise in self-sufficiency! (Thank JB!)

  6. #6
    Senior Member
    Join Date
    Apr 2009
    Location
    Canada
    Posts
    123
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: string clean up

    Again, thx for the valuable C advice sir!

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Search Engine Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Resources saved on this page: MySQL 10.71%
vBulletin Optimisation provided by vB Optimise v2.6.4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.2.8 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominate (Lite) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 08:06 PM.

Copyright BetaSoft Inc.