Like Tree4Likes
  • 1 Post By Salem
  • 3 Post By jwroblewski44

string operation

This is a discussion on string operation within the C Programming forums, part of the General Programming Boards category; which is the most reliable functions that accept String in C..Ps:A string should end with a delimiter '

Like Tree4Likes
  • 1 Post By Salem
  • 3 Post By jwroblewski44

Thread: string operation

'.... I use ...

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

    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,681
    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,558
    > 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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User
    Join Date
    Aug 2012
    Posts
    73
    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,681
    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
    2,760
    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
    73
    no expert comments please

  8. #8
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,558
    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.
    progmateur likes this.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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

  10. #10
    Registered User
    Join Date
    Aug 2012
    Posts
    73
    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, 03: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, 01:54 AM
  5. Really basic string operation
    By bobthebullet990 in forum C Programming
    Replies: 6
    Last Post: 11-28-2005, 04:18 PM

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