char arrays, "cutting", resizing etc.

This is a discussion on char arrays, "cutting", resizing etc. within the C Programming forums, part of the General Programming Boards category; Originally Posted by CommonTater Don't be changing the colons to semi-colons like that... Editing quoted text is some serious bad ...

  1. #16
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by CommonTater View Post
    Don't be changing the colons to semi-colons like that...
    Editing quoted text is some serious bad juju.
    Increase your font size. They look like : to me.


    Quzah.
    Hope is the first step on the road to disappointment.

  2. #17
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682
    I absolutely donít have clue what the colon youíre talking about! I asked you question and you give some random :-/

    ssharish
    Life is like riding a bicycle. To keep your balance you must keep moving - Einstein

  3. #18
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682
    Quote Originally Posted by CommonTater View Post
    Don't be changing the colons to semi-colons like that...
    Editing quoted text is some serious bad juju.
    I absolutely donít have clue what the colon youíre talking about! I asked you question and you give some random :-/

    ssharish
    Life is like riding a bicycle. To keep your balance you must keep moving - Einstein

  4. #19
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,579
    The quote tags put the text in italics. With a smaller font size, the regular colon ( : ) looks like a semi-colon ( ; ), hence Tater's confusion.
    Last edited by anduril462; 06-20-2011 at 05:26 PM. Reason: Removed cursed smilies!

  5. #20
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by ssharish2005 View Post
    Why do you think this code will work? I say it wont and shall leave it to you to workout why?

    ssharish
    Ok... what makes you think it won't? Did you even bother to try it?

  6. #21
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    My guess is that he's assuming name will have whitespace.


    Quzah.
    Hope is the first step on the road to disappointment.

  7. #22
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by quzah View Post
    My guess is that he's assuming name will have whitespace.
    Quzah.
    But that's not in evidence from the examples provided.

  8. #23
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by CommonTater View Post
    But that's not in evidence from the examples provided.
    I know. I'm just guessing.


    Quzah.
    Hope is the first step on the road to disappointment.

  9. #24
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by quzah View Post
    I know. I'm just guessing.
    Quzah.
    LOL... so it doesn't matter if my suggestion would work or not... ???

  10. #25
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682
    Mate it wont work! Have you compiling your suggesting before posting?

    ssharish
    Life is like riding a bicycle. To keep your balance you must keep moving - Einstein

  11. #26
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    It's not going to work because %s will happily read the : as part of the string, leading to Very Bad Things, is where we're going here I think.

  12. #27
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682
    Quote Originally Posted by tabstop View Post
    It's not going to work because %s will happily read the : as part of the string, leading to Very Bad Things, is where we're going here I think.
    I was expecting an answer of him Tabstop lol. Anyway you got the whole thread to an end.

    ssharish
    Life is like riding a bicycle. To keep your balance you must keep moving - Einstein

  13. #28
    Registered User
    Join Date
    Apr 2006
    Posts
    2,053
    Even ssharish2005's code will lead to buffer overruns if the input is not formatted correctly and all the string part buffers are not 104 characters or longer. You really do need width fields for anything with %s or %[].
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  14. #29
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682
    Quote Originally Posted by King Mir View Post
    Even ssharish2005's code will lead to buffer overruns if the input is not formatted correctly and all the string part buffers are not 104 characters or longer. You really do need width fields for anything with %s or %[].
    Well yeah, if you know the fixes length. If you dont know the actual length of the string you want to read, you pretty much dont have an options unless you use %[].

    ssharish
    Life is like riding a bicycle. To keep your balance you must keep moving - Einstein

  15. #30
    Registered User
    Join Date
    Apr 2006
    Posts
    2,053
    Quote Originally Posted by ssharish2005 View Post
    Well yeah, if you know the fixes length. If you dont know the actual length of the string you want to read, you pretty much dont have an options unless you use %[].

    ssharish
    No, even then you need %N[], with N limmited by the size of the target buffer, or else you can buffer overflow. If you're using fgets followed by sscanf, you can make all your buffers the max line length, but otherwise you need the width specifier. The advantage to the no width specifier method is you don't have a magic number as a string literal.
    Last edited by King Mir; 06-21-2011 at 11:53 AM.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. "Switch", "int" and "char"!
    By luckyluke in forum C Programming
    Replies: 6
    Last Post: 07-29-2010, 10:42 AM
  2. scanf "%as" (dynamic char arrays)
    By brightmatter in forum C Programming
    Replies: 10
    Last Post: 03-05-2010, 11:05 PM
  3. Char Help! "Packing " bits to a signle unsigned char
    By xxrexdartxx in forum C Programming
    Replies: 7
    Last Post: 10-11-2009, 04:45 AM
  4. "itoa"-"_itoa" , "inp"-"_inp", Why some functions have "
    By L.O.K. in forum Windows Programming
    Replies: 5
    Last Post: 12-08-2002, 07:25 AM
  5. "CWnd"-"HWnd","CBitmap"-"HBitmap"...., What is mean by "
    By L.O.K. in forum Windows Programming
    Replies: 2
    Last Post: 12-04-2002, 06:59 AM

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