Thread: Line Parsing and this loop

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    7

    Line Parsing and this loop

    The user enters a set of characters, that i copy into an array right.

    Then i have a loop which goes through the characters, and when it finds a space, it breaks

    so i have the if statement for that set up like this...


    if (userentry[index] == ' '){
    break;
    }

    and i have tried varients such as

    asciivalue = 32; /Noting that 32 is a space in ascii/
    pointer = &asciiavalue;
    spacechar = *pointer;

    if (userentry[index] == spacechar){
    break;
    }

    and also..

    spacechar = ' ';
    if (userentry[index] == spacechar){
    break;
    }


    Yet, none of them work, so if anyone has a suggestion, could you please help me?
    Last edited by Joshua-NSW; 11-14-2001 at 02:54 AM.

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    7
    BTW its in C (obviously considering this is the C board)
    and its written in DEV C++ by bloodshed

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    247
    Code:
    char string[ ]="This,should,break,after,the,space if not you have this";
    int len, i = 0;
    
    len = strlen(string);
    while(i < len)
    {
       putchar(string[i]);
       if(string[i]==' ') break;
       i++;
    }
    This should work, if not it maybe down to how you are storing the characters in the array.
    Last edited by bigtamscot; 11-14-2001 at 03:30 AM.
    hoping to be certified (programming in c)
    here's the news - I'm officially certified.

Popular pages Recent additions subscribe to a feed