Please send a program in c..which aceppts the IP address in the form(for ex: 153.18.8.105) and converts it into 32bit long interger(ex.2568095849) using strtok library function and unions.
14 17702
Please send a program in c..which aceppts the IP address in the form(for ex: 153.18.8.105) and converts it into 32bit long interger(ex.2568095849) using strtok library function and unions.
Hi,
Please read posting guidelines
Hope this link helps to achieve your problem solution.
Regards
Hi,
Instead of blind posting ur questions try to get the idea about how inet_addr works and try to understand strtok to write the code.
Raghuram
Hi ,
Sample code to convert ip address from string to Long. But for better solution try to use the in built function.
Code snipped - please refrain from spoonfeeding.
Regards
Kin Parmar
Am Learning now Pls help me..
Am Learning now Pls help me..
Did you read zodilla58 and gpraghuram's responses? Did you look through the links, and did you read the Posting Guidelines of this site? Zodilla has already offered a link to the resource you need, why not look through that and start playing around with it? It's the best way to learn. Then when you have a more specific question, you can post again...
Am Learning now Pls help me..
We don't consider copying and pasting spoonfed code 'learning' ... please give it
a try yourself first and when you're stuck feel free to ask specific questions here;
we're willing to help you then.
kind regards,
Jos
hello, pls look in to my program
and help me to modify this.... -
#include <stdio.h>
-
#include <string.h>
-
#include<stdlib.h>
-
-
main()
-
{
-
int x = 1,z;
-
long l,k;
-
char str[]=" 153.18.8.105";
-
char *str1;
-
char str2[16];
-
-
printf("String: %s\n", str);
-
str1 = strtok(str, ".");
-
strcpy(str2,str1);
-
-
while (1)
-
{
-
-
str1 = strtok(NULL, ".");
-
-
-
if (str1 == NULL)
-
{
-
-
exit(0);
-
}
-
strcat(str2,str1);
-
l=atol(str2);
-
printf("long integer is %ld \n",l);
-
}
here i tried some what......the thing is i dont knoe structure and union...
how to get the input string from user i.e the ip address using struct/union..pls guide me
Hi,
Please read posting guidelines
Hope this link helps to achieve your problem solution.
Regards
Reading through things other people have posted will save you quite a bit of time. Why not use the library available to you?
Why do you need to use a union or struct? We need a better explanation of what and how you are trying to do before we can give you more help.
A lotta folks just keep using strtok(). I want to say that strtok() works because it uses a static variable. That static variable makes strtok() a disaster in a multi-threaded program where the same strtok() could be simultaneously called on separate threads creating a race condition.
Any progam using static or global variables is not thread safe and has to remain a single-threaded program.
This is a problem since most modern software is multithreaded.
Just keep this in mind when you use this thing.
I was asked to do with structure/union....what to do....how to modify pls help
Why should you go for strtok() to convert those IP addresses?
You can just make use of htonl() and htons()..
regards,
Vinoth
Why should you go for strtok() to convert those IP addresses?
You can just make use of htonl() and htons()..
regards,
Vinoth
I was unaware of that library when I suggested srtok(), it would be much easier to use those, if the OP's assignment allows for them - they have yet to clarify why they need to use a union.
Please send a program in c..which aceppts the IP address in the form(for ex: 153.18.8.105) and converts it into 32bit long interger(ex.2568095849) using strtok library function and unions.
i wil tell u the logic. u have to implement. using strtok u make seperate strings and then u use atoi function and convert it to integer. Then convert each integer to bianry. then concatenete all four binary nos. then convert that whole binary no into decimal no. that gives u the 32-bit long int.
i wil tell u the logic. u have to implement. using strtok u make seperate strings and then u use atoi function and convert it to integer. Then convert each integer to bianry. then concatenete all four binary nos. then convert that whole binary no into decimal no. that gives u the 32-bit long int.
That was what I was originally thinking as well, but it would be easier for the OP to include the above library and use one function to 'just do it' and not re-implement something that is already out there.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Joseph Suprenant |
last post by:
I have an array of unsigned chars and i would like them converted to
an array of ints. What is the best way to do this? Using RedHat 7.3
on an Intel Pentium 4 machine. Having trouble here, hope...
|
by: Golan |
last post by:
Hello,
I have a hexa file which I need to convert to decimal.
I use memcpy into variables (char for one octet, short for 2 octets
and int for 4 octets) and then print the value into the file by...
|
by: Martin Pöpping |
last post by:
Hello,
I´ve a problem with the follwing code lines:
string line;
ifstream myfile ("doorcoordinates.txt");
if (myfile.is_open())
{
char str;
char * pch;
|
by: kyle.tk |
last post by:
I am trying to write a function to convert an ipv4 address that is held
in the string char *ip to its long value equivalent. Here is what I
have right now, but I can't seem to get it to work.
...
|
by: UKuser |
last post by:
Hi Guys,
I have a program which converts Excel spreadsheets to Javascript and
allows interactivity. However it can't convert it to PHP, which is
obviously better for users to view (in case J/S...
|
by: Spitfire |
last post by:
Hi All,
I've this weird question about pointers. I would like to know how to
return the address of a local variable, safely!! Isn't that a
unrecommended procedure? Doesn't it have possibilities...
|
by: Alan |
last post by:
How do I convert the type const char* to type char*?
I have an input string ("input_string") of class string. I need
to convert this to type char* in order to use it in a call to the
strtok()...
|
by: kakolibora |
last post by:
How to convert an IP address to it's equivalent 32 bits long integer using unions and strtok library function? Please help me.
|
by: Ajay |
last post by:
Hi All,
I got a segmentation fault while accessing a structure element.
I pasted the output from gdb and the backtrace.
However if I am able successfully access the structure using the...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |