day16 - More text processing 1 Strings and char * Recall...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
    1 More text processing
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
    2 Strings and  char * Recall that array names are simply the address of the first element of the array. This means that strings are nothing more than a pointer to some character (or char * ). Starting from that character, you should eventually reach the null character. '\0' 5 'o' 'l' 'l' 'e' 'h' 4 3 2 1 0 word:
Background image of page 2
    3 Strings and  char * However, you can't just replace all character arrays with char * . For example, when reading a string, you have to allocate a buffer to store the string. char buffer[1000]; scanf("%s", buffer);
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
    4 Strings and  char * What happens if you replace the variable declaration with char *buffer ? char *buffer; scanf("%s", buffer); The pointer buffer was never initialized, so it points to some random location in memory, which doesn't belong to you! buffer: ?
Background image of page 4
    5 Functions that return  char * Some functions that operate on strings return pointers to the middle of the parameter string. The return value could indicate that the individual character at that position is of significance the character marks the beginning of a substring of interest
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
  6 strchr  – Search for character in string strchr takes two parameters: a string and a character. Returns
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/29/2009 for the course EE 142 taught by Professor Bensollimketkai during the Spring '09 term at Washington State University .

Page1 / 18

day16 - More text processing 1 Strings and char * Recall...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online