Thread: convert int to char *

  1. #1
    Unregistered
    Guest

    convert int to char *

    hi guys...

    can you please help me with this.

    am currently doing a client-server program...a tcp port scanning.

    actually am doing great with this work...but i got stuck with this part...

    int rd;
    void sendMessage(char ........end, char *host, int port)
    {
    while(1)
    {
    rd = sendto(sd,ssend,strlen(ssend)+1,0,(struct sockaddr *) &servAddr,sizeof(servAddr));
    if(rd<0) {
    printf("cannot send data \n");
    exit(1);
    }
    printf("%s:%i:%s\n",host,port,ssend );
    break;
    }

    ---the problem with this, im supposed to combine the char* host, char ........end and the int port in a one long char* ssend (or string) for me to send it in the sendto function. is there anyway for me to concatenate the char* ssend, the char* host and the int port (this is my problem) in a long string? or how do you convert an int to a string so that i can use the strcat function? thanks...

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Since you already know how to use print, just take a look at sprintf().

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    22

    Thumbs up convert int to char *

    hello man,
    u can use the function 'itoa(int intvariable, char *charvariable, int total_no_of_char_convert)'

    example:
    int i=10;
    char ch[80];
    itoa( i, ch, 40 );

    thanx...
    take care...
    _________
    Jackie

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    itoa() is not an ANSI function, and may not be compatible or even included with your compiler.

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  2. can some one please tell me the cause of the error ?
    By broli86 in forum C Programming
    Replies: 8
    Last Post: 06-26-2008, 08:36 PM
  3. Replies: 8
    Last Post: 03-10-2008, 11:57 AM
  4. How do i un-SHA1 hash something..
    By willc0de4food in forum C Programming
    Replies: 4
    Last Post: 09-14-2005, 05:59 AM
  5. easy if you know how to use functions...
    By Unregistered in forum C Programming
    Replies: 7
    Last Post: 01-31-2002, 07:34 AM