-4

Trying to write the following function but confused, as get() only reads in the first character?

Write C-string's chars to the screen one char at a time.

void writeString(const char*)

Rule:
cannot use [].

Hints:use put();

make use of '\0' – but don't write it out.

NirMH
  • 4,769
  • 3
  • 44
  • 69
user3019579
  • 71
  • 10
  • I think others have done this same homework. You should try searching for it. – crashmstr May 14 '14 at 19:10
  • Why are you worrying about `get` and reading in, when you're supposed to *write* and the hint says to use `put`? Both of those are the opposite of what you're asking. – molbdnilo May 14 '14 at 19:25

1 Answers1

1

It sounds like you just need a simple loop to output the string. Something like this perhaps.

void writeString(const char* str)
{
    while(str++ != '\0') put(*str);
}

The while(str++ != '\0') will iterate over the string buffer pointed to by str and output each character. It also increments the str pointer to the next character and checks for null terminator ('\0').

Captain Obvlious
  • 19,754
  • 5
  • 44
  • 74