pointer to char

This is a discussion on pointer to char within the C Programming forums, part of the General Programming Boards category; hi i'm evaluating a string. ppos (char *) points to the beginning. it's assured that '"' or ' ' occures ...

  1. #1
    Registered User stormbringer's Avatar
    Join Date
    Jul 2002
    Posts
    90

    pointer to char

    hi

    i'm evaluating a string. ppos (char *) points to the beginning. it's assured that '"' or ' ' occures befor the beginning of the string is reached. however, whats wrong with this expression

    Code:
    	plen=0;
    	while(*(ppos+plen) != ' ' || *(ppos+plen) != '"')
    		++plen;
    	strncpy(line2,ppos,plen);
    it should get the lengt of a pattern till '"' or ' ' is reached. however it doesn't do anything but just increasing plen (size_t) and looping endless.

    thanks

  2. #2
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    Code:
    while(*(ppos+plen) != ' ' || *(ppos+plen) != '"')
    	++plen;
    This loop will loop forefer:
    Code:
    while(a != 1 || a != 2)
    Try && instead.

  3. #3
    Registered User stormbringer's Avatar
    Join Date
    Jul 2002
    Posts
    90
    thanks, stupid error

  4. #4
    Registered User Joe Monti's Avatar
    Join Date
    Feb 2003
    Posts
    20
    It's also a really good idea to check for '\0' just in case. But it depends on how certain it will have the ' ' or '"'
    - Joseph Monti
    __________________
    This message is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation. For more info visit http://joe.tgpr.org/

  5. #5
    Registered User stormbringer's Avatar
    Join Date
    Jul 2002
    Posts
    90
    that's done before. i assure that it is a valid string, so checking for '\0' would just be an overhead.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 04:23 AM
  2. Direct3D problem
    By cboard_member in forum Game Programming
    Replies: 10
    Last Post: 04-09-2006, 03:36 AM
  3. Program Crashing
    By Pressure in forum C Programming
    Replies: 3
    Last Post: 04-18-2005, 10:28 PM
  4. Could somebody please help me with this C program
    By brett73 in forum C Programming
    Replies: 6
    Last Post: 11-25-2004, 01:19 AM
  5. towers of hanoi problem
    By aik_21 in forum C Programming
    Replies: 1
    Last Post: 10-02-2004, 01:34 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21