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, 1048👍, 0💬
Popular Posts:
What will be printed as the result of the operation below: main() { char *ptr = " Cisco Systems"; *p...
What is the result of using Option Explicit? When writing your C program, you can include files in t...
How To Enter Numeric Values as HEX Numbers? - MySQL FAQs - Introduction to SQL Basics If you want to...
How To Use SELECT Statement to Count the Number of Rows? - Oracle DBA FAQ - Understanding SQL SELECT...
Rachel opened her math book and found that the sum of the facing pages was 245. What pages did she o...