Strings Parameters and Return Values

Strings Parameters and Return Values - • make sure that s...

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

View Full Document Right Arrow Icon
Strings Parameters and Return Values void modify1(const char *s, char **news) { /* return through parameter a copy of s modified*/ if(s == NULL) return; *news = strdup(s);
Background image of page 1

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

View Full DocumentRight Arrow Icon
9: Formatted String I/0 The format control string %s is used for string I/O. Leading whitespace characters are skipped in a search for the first non-whitespace character, and input stops when a word is read (a word is a sequence of characters not containing any whitespace).
Background image of page 2
string io To input a string: use scanf("%s", s) rather then
Background image of page 3

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

View Full DocumentRight Arrow Icon
Background image of page 4
Background image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: • make sure that s is initialized; i.e. there is some memory allocated for s (for example, Read a Single Word (at most 10 characters): • if(scanf("% 10 s", s) != 1) • error • int lower(char *s) { /* return number of l.c. letters */ • int i; • char *q; • for(i = 0, q = s; *q; q++) • if(islower(*q)) • i++; • return i; • } • int main() { • const int M = 10; • char *p; • if((p = calloc(M + 1, sizeof(char)) == NULL) • return EXIT_FAILURE; • if(scanf("% 10 s", p) == EOF)...
View Full Document

This note was uploaded on 02/18/2012 for the course CS 240 taught by Professor Rego during the Fall '08 term at Purdue.

Page1 / 5

Strings Parameters and Return Values - • make sure that s...

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

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