Angel David Yaguana Hernandez
/
CPP_strchr
strchr, descripcion y ejemplo
main.cpp@0:8b9477b27450, 2012-04-03 (annotated)
- Committer:
- sherckuith
- Date:
- Tue Apr 03 21:04:22 2012 +0000
- Revision:
- 0:8b9477b27450
strchr, descripcion y ejemplo
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sherckuith | 0:8b9477b27450 | 1 | #include "mbed.h" |
sherckuith | 0:8b9477b27450 | 2 | /* strchr example */ |
sherckuith | 0:8b9477b27450 | 3 | #include <stdio.h> |
sherckuith | 0:8b9477b27450 | 4 | #include <string.h> |
sherckuith | 0:8b9477b27450 | 5 | |
sherckuith | 0:8b9477b27450 | 6 | int main () |
sherckuith | 0:8b9477b27450 | 7 | { |
sherckuith | 0:8b9477b27450 | 8 | char str[] = "This is a sample string"; |
sherckuith | 0:8b9477b27450 | 9 | char * pch; |
sherckuith | 0:8b9477b27450 | 10 | printf ("Looking for the 's' character in \"%s\"...\n",str); |
sherckuith | 0:8b9477b27450 | 11 | pch=strchr(str,'s'); |
sherckuith | 0:8b9477b27450 | 12 | while (pch!=NULL) |
sherckuith | 0:8b9477b27450 | 13 | { |
sherckuith | 0:8b9477b27450 | 14 | printf ("found at %d\n",pch-str+1); |
sherckuith | 0:8b9477b27450 | 15 | pch=strchr(pch+1,'s'); |
sherckuith | 0:8b9477b27450 | 16 | } |
sherckuith | 0:8b9477b27450 | 17 | return 0; |
sherckuith | 0:8b9477b27450 | 18 | } |
sherckuith | 0:8b9477b27450 | 19 | |
sherckuith | 0:8b9477b27450 | 20 | /* |
sherckuith | 0:8b9477b27450 | 21 | Output: |
sherckuith | 0:8b9477b27450 | 22 | |
sherckuith | 0:8b9477b27450 | 23 | Looking for the 's' character in "This is a sample string"... |
sherckuith | 0:8b9477b27450 | 24 | found at 4 |
sherckuith | 0:8b9477b27450 | 25 | found at 7 |
sherckuith | 0:8b9477b27450 | 26 | found at 11 |
sherckuith | 0:8b9477b27450 | 27 | found at 18 |
sherckuith | 0:8b9477b27450 | 28 | */ |