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
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
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
> 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.
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
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
that way you are telling scanf to read up to 30 characters...Code:scanf("%30s", s);
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
What? GCC is not Turbo-C++, so if your university only allows gcc why are you using Turbo-Crap?Our University only allows GCC standered thus only allows us to use Turbo CPP.....
Jim
no expert comments please
Nothing is safe until you allocate memory for s.my question was what is the most reliable function to accept string
1.char *s;
scanf("%s",s);
2.gets()
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.
thanks for rectifying...you all are right ...my fault