Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
Does C have anything like the `substr extract substrin routine present in other languages?
Does C have anything like the `substr extract substrin routine present in other languages?
✍: Guest
Not as such. To extract a substring of length LEN starting at index POS in a source string, use something like
char dest[LEN+1];
strncpy(dest, &source[POS], LEN);
dest[LEN] = '\0'; /* ensure \0 termination */
char dest[LEN+1] = "";
strncat(dest, &source[POS], LEN);
or, making use of pointer instead of array notation,
strncat(dest, source + POS, LEN);
(The expression source + POS is, by definition, identical to &source[POS]
2016-03-07, 1152👍, 0💬
Popular Posts:
What does AddressOf operator do in background ? The AddressOf operator creates a delegate object to ...
How To Change the Password of Another User Account? - MySQL FAQs - Managing User Accounts and Access...
How does one iterate through items and records in a specified block? One can use NEXT_FIELD to itera...
What is V model in testing? V model map’s the type of test to the stage of development in a project....
What invokes a thread's run() method? After a thread is started, via its start() method of the Threa...