Thread: string operation

  1. #1
    Registered User
    Join Date
    Aug 2012
    Posts
    77

    string operation

    which is the most reliable functions that accept String in C..Ps:A string should end with a delimiter '\0'....
    I use Turbo CPP .....
    please provide me with the answer asap

  2. #2
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    I have heard about string.h, but I do not know if that is what you are looking for.. I prefer not using String in C.
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > I use Turbo CPP .....
    Let me stop you right there.

    Visual Studio Express 2012 Products | Microsoft Visual Studio
    smorgasbordet - Pelles C
    Code::Blocks
    Orwell Dev-C++ | Free Development software downloads at SourceForge.net

    > which is the most reliable functions that accept String in C.
    fgets() is the only (really simple) way.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Aug 2012
    Posts
    77
    Our University only allows GCC standered thus only allows us to use Turbo CPP.....
    I know how to include header file string.h but thats not my question...
    my question was what is the most reliable function to accept string

    1.char *s;
    scanf("%s",s);

    2.gets()

    I know these two but sometime they fail to work...so I want a more reliable function to accept string from the user

  5. #5
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    When I see gets with the world reliable I start feeling bad. The reason is here. Hackers love when people use gets.

    As noted before, you should use fgets, or because you may not be allowed to use it now, you could use scanf like this
    Code:
    scanf("%30s", s);
    that way you are telling scanf to read up to 30 characters...
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  6. #6
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Our University only allows GCC standered thus only allows us to use Turbo CPP.....
    What? GCC is not Turbo-C++, so if your university only allows gcc why are you using Turbo-Crap?

    Jim

  7. #7
    Registered User
    Join Date
    Aug 2012
    Posts
    77
    no expert comments please

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    my question was what is the most reliable function to accept string

    1.char *s;
    scanf("%s",s);

    2.gets()
    Nothing is safe until you allocate memory for s.
    No, not even fgets() can save you if you don't know what you're doing.

    > Our University only allows GCC standered thus only allows us to use Turbo CPP.....
    Ah, from India I guess.
    Read this
    Yes, TurbidCrap is institutionalised madness, because nobody will ever get fired for teaching it.
    But if you want to get ahead, then do yourself a favour and learn how to use another compiler apart from TC.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  9. #9
    young grasshopper jwroblewski44's Avatar
    Join Date
    May 2012
    Location
    Where the sidewalk ends
    Posts
    294
    Quote Originally Posted by progmateur View Post
    no expert comments please
    What? <people who can help, need not apply>

  10. #10
    Registered User
    Join Date
    Aug 2012
    Posts
    77
    thanks for rectifying...you all are right ...my fault

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need algorithm for string operation
    By mistu4u in forum C Programming
    Replies: 5
    Last Post: 06-18-2011, 02:54 PM
  2. recursive string operation..
    By transgalactic2 in forum C Programming
    Replies: 72
    Last Post: 01-09-2009, 04:42 PM
  3. Which string operation is faster? Which is better?
    By 6tr6tr in forum C++ Programming
    Replies: 4
    Last Post: 04-02-2008, 11:15 AM
  4. string operation and related exception
    By George2 in forum C++ Programming
    Replies: 63
    Last Post: 03-04-2008, 02:54 AM
  5. Really basic string operation
    By bobthebullet990 in forum C Programming
    Replies: 6
    Last Post: 11-28-2005, 05:18 PM