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

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

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

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

View Full Document Right 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:
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);
Image of page 3

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

View Full Document Right 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: ?
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
Image of page 5

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern