I am writing a C program and need to use the equivalent of the C++ substring function to return the 1st 10 characters of a string. Does C have something similar or has anyone had to write their own function?
first 10 char:
sprintf(outbuff,"%.10s",inbuff);
10 char starting by 3 char 0f inbuff:
sprintf(outbuff,"%.10s",&inbuff[3]);
or if pointers:
sprintf(outbuff,"%.10s",inbuff+3);
-----------
when they don't ask you anymore, where they are come from, and they don't tell you anymore, where they go ... you'r getting older !
Just for information - although its probably not so important these days with fast processors...printf and all its variants (sprintf, fprintf etc) is very inefficient. strcpy, strncpy or memcpy are far more efficient in operation.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.