need to read data from UDP socket


Results 1 to 4 of 4

Thread: need to read data from UDP socket

  1. #1
    Join Date
    Apr 2008
    Posts
    4

    need to read data from UDP socket

    I am developing an application to receive data using UDP socket.
    My data may be in the form 123ABcD123
    I face problem in converting a decimal number(ANSI equivalent of a char) to its correspoding char...?

    Like::: 65 stands for A,66 stands for B

    i have a pointer to array of int containing :

    65,66,67,68
    which stands for
    A,B,C,D

    Is there any function which can convert those dec to char in C language ?
    P.s) I cannot use itoa() because my gcc compiler states that it is not defined even after i have included stdlib.h

    Is there someone who can help me in this...
    Any help would be highly appreciated...
    thank you...

  2. #2
    Join Date
    Sep 2002
    Location
    Canada
    Posts
    565
    Not sure if this is what you're trying to do but it seems like it works for some applications. It's not decimal to ascii it's the reverse but maybe you can figure something out with it.

    http://forums.devshed.com/c-programm...des-48771.html

    I also found a chart you probably already have that may help you out if you don't.
    http://www.pcguide.com/res/tablesASCII-c.html

    You could also key an array with the decimal values and enter the ASCII character as the keys value.

    I also found this on IBMs website. These functions are not part of ANSI C. They require IBM libraries. You could either find a copy of the library and link it or find the function definition and recode it for your purposes.
    http://publib.boulder.ibm.com/infoce...glinf0060.html

    This is the function I think you want.
    decfcvt( ) Converts DECIMAL value to ASCII string

    Some people over at ExpertsExchange have coded a function for someone to use. Sign up as an expert and you can get a free account. Here is the post I found
    http://www.experts-exchange.com/Prog..._20563466.html

    I hope something here helps you.
    Last edited by acid45; 04-25-2008 at 01:27 PM.
    "Getting information from the internet is like taking a drink from a fire hydrant." - Mitchell Kapor

  3. #3
    Join Date
    May 2001
    Location
    Uh, I'm somewhere where I don't know where I am.
    Posts
    1,228
    Are you sending ascii 65666778 or are you sending ABCD?

    If you are sending ascii ABCD, then when you recv, place the data into a char array. The code will take care of itself. If you place ascii A into an int and out put that, it'll be 65. Here's a little test program to run to see what I am talking about.

    Code:
    #include <stdio.h>
    
    int main() {
        int i = 'A';
        char ch = 65;
        char buf[5] = { 65, 66, 67, 68, 0 };
        printf("Here is an int \'A\': %i\n", i);
        printf("Here is a char 65: %c\n", ch);
        printf("Here is the char array: %s\n", buf);
    }
    if (i_forgot && this_is_about_code)
    language = c++;

  4. #4
    Join Date
    Apr 2008
    Posts
    4
    Thats the stuff i wanted.
    Thanks a lot for the example tecknophreak...

    Thank u acid45 for the links... Nice reading...

Posting Permissions

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