isprint

Write your question.
in while loop str takes one character at a time.so after completing the string first line ,it takes only '\' so it is printable one...so it has also be printed then 'n'.so total content has to be print right.but here not the case only first line is printed why so?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
  Put the code you need help with here.
/* isprint example */
#include <stdio.h>
#include <ctype.h>
int main ()
{
  int i=0;
  char str[]="first line \n second line \n";
  while (isprint(str[i]))
  {
    putchar (str[i]);
    i++;
  }
  return 0;
}
'\n' is called escape sequence, see:

http://en.cppreference.com/w/cpp/language/escape

Hence \n is transformed into a single character where isprint(...) returns 0.
Topic archived. No new replies allowed.