Thread: strings

  1. #1
    Blank
    Join Date
    Aug 2001
    Posts
    1,034

    strings

    I am busy writing a program that takes in lines of text from 2 seperate files and writes them to a third if they are different, as of yet I have not been able to test my program, because my other comps down at the mo and this one's a borrowed one of a mate and its all USB ports, so RedHat 7.0 won't work

    What i would like to know, as i am just trying to go through the program in my head thinking of instance that might cause probs.

    If i am reading lines of text into a string that says bas a buffer lenght of 80, will i need to clear that sting before reading in the next line, because thinking it would still have the last string in.

    how do i clear the string if this is the case.
    thanks
    -ali

  2. #2
    Anti-Terrorist
    Join Date
    Aug 2001
    Location
    mming, Game DevelopmentCSR >&<>&2Minimization of boolean functions, PROM,PLA design >&0>&WA, USA guitar, dogsCommercial Aviation >&>>&USAProgramming
    Posts
    742
    Try memset()
    -initialize it with '\0' 's
    -size_t can be sizeof(array)



    Last edited by Witch_King; 08-13-2001 at 10:43 PM.
    I compile code with:
    Visual Studio.NET beta2

  3. #3
    junior member mix0matt's Avatar
    Join Date
    Aug 2001
    Posts
    144

    memset certainly works, but...

    memset will do exactly what you wanted to, but...

    I really can see no reason for you to even worry about clearing the buffer. You're still writing 80 bytes, and you're never going to see anything past the '\0' character in the string. I'd bee more concerned with overwriting your buffer. It seems like a wasted function call to me, but I really don't know everything now do I?
    THIS IS NOT JUST A CHRONICLING OF THINGS WE HAVE DONE IN THE PAST BUT OUR RISE TO POWER.

  4. #4
    Blank
    Join Date
    Aug 2001
    Posts
    1,034
    This is cool I have people impersonationg me!










    Main returns int! Did someone get code from msdn?

  5. #5

  6. #6

  7. #7
    Anti-Terrorist
    Join Date
    Aug 2001
    Location
    mming, Game DevelopmentCSR >&<>&2Minimization of boolean functions, PROM,PLA design >&0>&WA, USA guitar, dogsCommercial Aviation >&>>&USAProgramming
    Posts
    742
    Okay, maybe I rushed to post a reply because this place has not been seeing any action. You can use memset to initialize an array, especially a dynamically allocated array. A automatic array is easy enough to initialize with a loop. In this program you probably don't need it memset. Maybe just define a buffer size of 256 which is the max of unsigned char, and than scan until you reach the newline character. If you want more protection than that, than you might have to reallocate your buffer but that means a lot more work and in most situations isn't necessary. It is more difficult to give advice when there is no code to base an answer on.
    Last edited by Witch_King; 08-13-2001 at 10:45 PM.
    I compile code with:
    Visual Studio.NET beta2

  8. #8
    Registered User
    Join Date
    Aug 2001
    Posts
    27
    I don't know what happened nick for some reason it posted as your name ??? strange

  9. #9
    Blank
    Join Date
    Aug 2001
    Posts
    1,034
    Yea I had it come up with you once but I just logged
    out.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strings Program
    By limergal in forum C++ Programming
    Replies: 4
    Last Post: 12-02-2006, 03:24 PM
  2. Programming using strings
    By jlu0418 in forum C++ Programming
    Replies: 5
    Last Post: 11-26-2006, 08:07 PM
  3. Reading strings input by the user...
    By Cmuppet in forum C Programming
    Replies: 13
    Last Post: 07-21-2004, 06:37 AM
  4. damn strings
    By jmzl666 in forum C Programming
    Replies: 10
    Last Post: 06-24-2002, 02:09 AM
  5. menus and strings
    By garycastillo in forum C Programming
    Replies: 3
    Last Post: 04-29-2002, 11:23 AM