isspace function in C

Hello,
I would like this program to stop reading at the first white space character. This is what I have so far. Is it right?

#include
#include

int read_line(char str[], int n)
{
char ch;
int i = 0;

while ((ch = getchar()) != '
')
if (i < n)
str[i++] = ch;

while(isspace(ch)) /* is this right? */
str[i] = '';

str[i] = ''
return i;
}

Comments

  • : Hello,
    : I would like this program to stop reading at the first white space character. This is what I have so far. Is it right?
    :
    : #include
    : #include
    :
    : int read_line(char str[], int n)
    : {
    : char ch;
    : int i = 0;
    :
    : while ((ch = getchar()) != '
    ')
    : if (i < n)
    : str[i++] = ch;
    :
    : while(isspace(ch)) /* is this right? */
    : str[i] = '';
    :
    : str[i] = ''
    : return i;
    : }
    :
    Hi,

    No: this is false. (I let you gess the right solution, because your matter is very easy to solve...).
    I help you: you need only one while loop with two conditions.
    More: after a str[i]='' you forgot the ";".

    Bye,

    Vincent.


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories