counting number of lines in my output file

This is a discussion on counting number of lines in my output file within the C Programming forums, part of the General Programming Boards category; Originally Posted by Elysia It's a shame not to use safe functions if they're available. Why not use them if ...

  1. #31
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by Elysia View Post
    It's a shame not to use safe functions if they're available. Why not use them if you have them? They were designed for a reason - to avoid some very common mistakes.
    If they were standard functions, I might use them. But for most of those "secure" functions, I can't see why they would be more secure than the standard C functions, assuming you're not a sloppy programmer.

  2. #32
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,985
    Irregardless if it's a Microsoft prank or whatever - they're safer than normal CRT functions and they're easy to do away with if you need portability.

    Quote Originally Posted by cpjust View Post
    If they were standard functions, I might use them. But for most of those "secure" functions, I can't see why they would be more secure than the standard C functions, assuming you're not a sloppy programmer.
    Plus, they can help you find bugs, especially when you write complicated code and pass a destination buffer not large enough to hold the data.
    Portability isn't an issue if you understand what you're doing. Usong Windows APIs and such is non-portable since they must be completely re-written, but "secure" functions only needs a wrapper or a define to wrap them to standard functions, so there's no issue here.

    If it's Microsoft only, then they have done us a great service in at least trying to provide a better runtime library without breaking too much code. I don't blame them and I certainly don't mind using them.
    Last edited by Elysia; 12-25-2007 at 06:38 PM.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #33
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    They're dumb...
    Quote Originally Posted by msnd pointlessness
    For example, the strcpy function has no way of telling if the string that it is copying is too big for its destination buffer. However, its secure counterpart, strcpy_s, takes the size of the buffer as a parameter, so it can determine if a buffer overrun will occur.
    Er... use strncpy()...

    They don't seem to be more 'secure', in fact they're merely n00b-friendly CRT functions. They even 'fix' gets() so you can use it 'safely'. Pfft, it's been established for a long time that they're unsafe and use the other CRT functions which already solve the problem (eg, gets() -> fgets(), strcpy() -> strncpy(), etc). M$ has done nothing but launched an attempt to break portability a bit more.
    Last edited by zacs7; 12-25-2007 at 06:53 PM.

  4. #34
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    And as I said before, strcpy() is safe if you're not careless.

    malloc() the buffer for what you need and guarentee the size will match. Otherwise, use static buffers, but make sure your static buffer being copied into is large enough to handle the entire buffer coming in. Bingo. Your buffer is large enough.

  5. #35
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Even the MS 'secure' functions can be insecure if you don't know how to use them properly. Just pass in the wrong size for a buffer size and boom!
    I avoid C like the plague, so I usually don't need to use those functions, but when I do use them, I read the docs thoroughly. The reason why they can be insecure is because people don't pay enough attention to the docs.

Page 3 of 3 FirstFirst 123
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need Help Fixing My C Program. Deals with File I/O
    By Matus in forum C Programming
    Replies: 7
    Last Post: 04-29-2008, 08:51 PM
  2. adding a number to a number
    By bigmac(rexdale) in forum C Programming
    Replies: 11
    Last Post: 10-24-2007, 01:56 PM
  3. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 04:44 PM
  4. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 04:30 PM
  5. Counting Number of Lines of file
    By dapernia in forum C Programming
    Replies: 1
    Last Post: 09-05-2003, 03:22 PM

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