My Tech notes: Short Sweet C Functions
Subscribe

Unix Documentation

Free Online Unix Training Materials

Lists many links to free Unix training materials.

Pointers and Arrays Materials

Pointers and Arrays materials Explained for C beginners

C FAQ and General Questions C Interview Questions

Powered By

Free XML Skins for Blogger

Powered by Blogger

Tuesday, July 29, 2008

Short Sweet C Functions

One of the short and sweet function which i have written in C language is dotted_decimal_to_string(). This function takes individual fields as inputs returns dotted decimal string. This is used in taking dotted decimal values of network parameters like IP address, IP netmask, IP gateway address, DNS server IP address etc, from the webpage, where these network parameters are individual inputs from a form.
Check out the function.

char *dotted_decimal_to_string(char *pad1, char *pad2, char *pad3, char *pad4)
{
char temp[40],*ret_string;

sprintf(temp,"%s.%s.%s.%s",pad1,pad2,pad3,pad4);

ret_string = (char*)malloc(strlen(temp) + 1);
strcpy(ret_string,temp);

return ret_string;
}
The return string is a dotted decimal value for a network parameter and is used to store in configuration file or to use for setting and configuring the Network parameters.
This function stuck to my mind while i was going to bed yesterday. That means, my back-office was working for me, and giving me such a cute solution.
Otherwise I dont keep solutions short, they are always complex for little task also. :-)

1 comment:

R.G said...

Hi friends ! want any information about Rajasthan technical university , Kota ?

Just join the largest community of RTU students and x-students plus a lot of faculties.

Join www.heyrtu.com

Come on join the discussion !

Post a Comment