Re: strcat strncat and strlen



You are not making any sense. Are you asking why strlen exists? It
should be obvious, even to you. How else do you find the length of a
zero terminated string?

C must not count '\0' as being part of a string. This is the simple code
I tried,

int main(void) {
size_t t;
char hello[]="hello world\n";
t=strlen(hello);
printf("%i",hello);
}
The integer returned was 12. When I removed the '\n' from the string
and recompiled 11 was the number returned.
Why in production code would someone want to know the length of a
string? That's what I am asking. Hence my inexperience speaks for itself.


.



Relevant Pages

  • Re: $| (undocumented) magic?
    ... And, I must admit, I learnt lots of useful techniques ... in a contest at terje the goal was a program ... obtained extending that string either on the left or on the right. ... shouldn't/wouldn't do such things in "production code", ...
    (comp.lang.perl.misc)
  • Re: can I use __FILE__ ,__LINE__ etc. in a code witout DEBUG defined?
    ... :A good practise is not to use __FILE__ in production code, ... Static memory is going to take no more space than dynamic memory, ... more space than just storing the string. ... take more space than the constant string would. ...
    (comp.lang.c)
  • Re: Python String Substitution
    ... > Is there a way to print "Right" using % substitution? ... One way would be to make an adapter to convert that string to a tuple: ... I wouldn't actually recommend using eval in production code, ...
    (comp.lang.python)
  • Re: Porting ADA source
    ... >> and should never be used in production code. ... > Advice that one could easily take too far. ... > because String and Integer were forbidden types! ...
    (comp.lang.ada)
  • Re: String cat algo
    ... Zero terminated string ... Any decent dynamic string library has reallocation "heuristics" to ... avoid too many realloc calls, ... > comparitive zero terminated string approach is a lot faster. ...
    (comp.lang.asm.x86)