Results 1 to 10 of 10

Thread: removing last 5 or 6 chars

  1. #1

    Thread Starter
    Fanatic Member nabeels786's Avatar
    Join Date
    Jul 2001
    Location
    New York
    Posts
    919

    removing last 5 or 6 chars

    ive got a ip like: <ip>:<port>

    i wanna strip teh :<port>

    there what i came up with

    Code:
    	bool passed=false;
    	for(int i=0;i<=strlen(server_name);i++){
    		if(passed){
    			*server_name=' ';
    		} else{
    			if(*server_name==':'){
    				*server_name=' ';
    				passed=true;
    			}
    		}
    		*server_name++;
    	}
    it returns the lst 8 with the port, and i cant figure out why
    Visit www.fragblast.com
    Gaming, forums, and a online RPG/Battle system




    (__Flagg) DOT NET? is this a Hindi Dating service?

  2. #2
    Frenzied Member
    Join Date
    Jul 2002
    Posts
    1,370
    Code:
    char *buf;
    buf = server_name;
    buf+=strlen(server_name) -1;
    while(*buf!=':'){
           *buf-- = 0x00;
    }
    *buf = 0x00;
    }
    voila...

  3. #3
    Fanatic Member prog_tom's Avatar
    Join Date
    May 2001
    Location
    Los Angeles and Little Rock
    Posts
    810
    what is 0x00?

    prog_tom
    JOIN THE REVOLUTION!!!! Dual T3 backedup science community.
    http://physics.sviesoft.com/forum

  4. #4

    Thread Starter
    Fanatic Member nabeels786's Avatar
    Join Date
    Jul 2001
    Location
    New York
    Posts
    919
    null character
    Visit www.fragblast.com
    Gaming, forums, and a online RPG/Battle system




    (__Flagg) DOT NET? is this a Hindi Dating service?

  5. #5
    Fanatic Member prog_tom's Avatar
    Join Date
    May 2001
    Location
    Los Angeles and Little Rock
    Posts
    810
    cool!! where do you see all these weird characters?

    prog_tom
    JOIN THE REVOLUTION!!!! Dual T3 backedup science community.
    http://physics.sviesoft.com/forum

  6. #6
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    Originally posted by prog_tom
    cool!! where do you see all these weird characters?
    They are at the end of every string.
    Baaaaaaaaah

  7. #7
    Fanatic Member prog_tom's Avatar
    Join Date
    May 2001
    Location
    Los Angeles and Little Rock
    Posts
    810
    how come I never seen any of them, previously?

    prog_tom
    JOIN THE REVOLUTION!!!! Dual T3 backedup science community.
    http://physics.sviesoft.com/forum

  8. #8
    Ya ya Baby!!!Me is Back
    Join Date
    Jul 2002
    Posts
    362
    0x00 = 0

    it's hexadecimal....

    and what you call weird character is ASCII caracter.

    in all C++ book it have an introduction about that.

  9. #9

    Thread Starter
    Fanatic Member nabeels786's Avatar
    Join Date
    Jul 2001
    Location
    New York
    Posts
    919
    Originally posted by jim mcnamara
    Code:
    char *buf;
    buf = server_name;
    buf+=strlen(server_name) -1;
    while(*buf!=':'){
           *buf-- = 0x00;
    }
    *buf = 0x00;
    }
    voila...
    it returns a blank
    Visit www.fragblast.com
    Gaming, forums, and a online RPG/Battle system




    (__Flagg) DOT NET? is this a Hindi Dating service?

  10. #10
    Frenzied Member
    Join Date
    Jul 2002
    Posts
    1,370
    huh? this code prints everything up to but not inclusing the ':'
    Code:
    #include <stdio.h>
    int main(){
     char server_name[100];
    
     char *buf;
     memset(&server_name,0x00,sizeof(server_name));
     strcpy(server_name,"101.101.0:asb");
     buf = server_name;
     buf+=strlen(server_name) -1;
     while(*buf!=':'){
           *buf-- = 0x00;
      }
     *buf = 0x00;
      printf("%s\n",server_name);
    }
    The only possible difference is that server_name here is an sz string.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width