pre: - array pos[3] containing the dots' position in the IP adress
- array IP[15] containing the IP string
post:- return 4 arrays xx[3], yy[3], zz[3], tt[3] containing the IP/4 digits
problem(remaining from 1st version): - unexpected result while checking using printf
example: - instead having "xx[3] = 123" am having 123:)
- third part of the IP 123 and some bizard char instead of 123
questions: - please help(if there is any other comment...)
CODE: -
int i, j;
-
int xxtemp =0 , yytemp = 0, zztemp = 0, mmtemp = 0;
-
int y = 0, z = 0, m = 0;
-
char xx[3], yy[3], zz[3], mm[3];
-
char IP[] = {'1','2','3','.','1','2','3','.','1','2','3','.','1','2','3'};
-
int pos[] = {3,7,11};
-
for(i = 0; i < 4; i++)
-
{
-
if(i == 0)
-
{
-
for(j = i; j < pos[i]; j++)
-
{
-
if(isdigit(IP[j]))
-
xx[j] = IP[j];
-
}
-
printf("xxx part\n");
-
printf("%s\n", xx);
-
}
-
else if(i == 1)
-
{
-
for(j = pos[i-1]+1; j < pos[i]; j++)
-
{
-
if(isdigit(IP[j]))
-
{
-
yy[y] = IP[j];
-
y++;
-
}
-
}
-
printf("yyy part\n");
-
printf("%s\n", yy);
-
}
-
else if(i == 2)
-
{
-
for(j = pos[i-1]+1; j < pos[i]; j++)
-
{
-
if(isdigit(IP[j]))
-
{
-
zz[z] = IP[j];
-
z++;
-
}
-
}
-
printf("zzz part\n");
-
printf("%s\n", zz);
-
}
-
else if(i == 3)
-
{
-
for(j = pos[i-1]+1; j < 15; j++)
-
{
-
if(isdigit(IP[j]))
-
{
-
mm[m] = IP[j];
-
m++;
-
}
-
}
-
printf("mmm part\n");
-
printf("%s\n", mm);
-
}
-
}
3 1584
here si a screenshot of the program output
pre: - array pos[3] containing the dots' position in the IP adress
- array IP[15] containing the IP string
post:- return 4 arrays xx[3], yy[3], zz[3], tt[3] containing the IP/4 digits
problem(remaining from 1st version): - unexpected result while checking using printf
example: - instead having "xx[3] = 123" am having 123:)
- third part of the IP 123 and some bizard char instead of 123
questions: - please help(if there is any other comment...)
CODE: -
int i, j;
-
int xxtemp =0 , yytemp = 0, zztemp = 0, mmtemp = 0;
-
int y = 0, z = 0, m = 0;
-
char xx[3], yy[3], zz[3], mm[3];
-
char IP[] = {'1','2','3','.','1','2','3','.','1','2','3','.','1','2','3'};
-
-
There's an easier way to do this: -
char xx[4], yy[4], zz[4], mm[4]; // include the \0
-
char *Ips[4] = {xx, yy, zz, mm};
-
char IP[] = "123.67.12.90";
-
-
int ind = 0; // index in Ips
-
int ind2 = 0; // index in xx, yy ,zz, mm
-
-
for (int x = 0; x < strlen(IP); x++)
-
{
-
if (IP[x] == '.')
-
{
-
Ips[ind][ind2] = '\0' // null terminate
-
ind++; // move on to next segment
-
ind2 = 0 // restart counter of segment to 0
-
}
-
else
-
{
-
Ips[ind][ind2] = IP[x];
-
ind2++;
-
}
-
}
-
Ips[ind][ind2] = '\0' // terminate final segment because there is no period
-
The segments of the Ip address will be stored in Ips.
thank you it's working with some small modifications :)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Troll |
last post by:
Hi,
I need to write a script which reads some data and reports the findings.
Just to give you an idea the structure is similar to the following.
Data input example:
HEADING 1
**********...
|
by: Jody Gelowitz |
last post by:
I am trying to find the definition of "Safe Printing" and cannot find out
exactly what this entitles. The reason is that I am trying to print
contents from a single textbox to no avail using the...
|
by: jacob navia |
last post by:
Has anyone here any information about how arrays can be
formatted with printf?
I mean something besides the usual formatting of each element
in a loop. I remember that Trio printf had some...
|
by: Jonathan DeCarlo |
last post by:
I have a situation where I need to override a method in
managed C++ that was originally defined in C#. The
method takes a parameter of an array of arrays of
doubles. Here is a simple examples...
|
by: John Peterson |
last post by:
Hello all!
I'm at my wits end trying to search for what I assumed to be a relatively
straightforward task. I have a Web application written in C#, and I have a
button on the form that I want to...
|
by: eskildb |
last post by:
First, please be gently. I am fairly new to the programming world (1.5
years with some expermentation prior to).
I have been working on a project that has to print HTML pages with
graphics in a...
|
by: eskildb |
last post by:
First, please be gently. I am fairly new to the programming world (1.5
years with some expermentation prior to).
I have been working on a project that has to print HTML pages with
graphics in a...
|
by: Siv |
last post by:
Hi,
I am getting into printing with VB.NET 2005 and want to implement the usual
capability that a user can select a selection of pages. I have a report
that is generated by my application that if...
|
by: =?Utf-8?B?TWFyazYyNA==?= |
last post by:
I have a web method that renders a SQL Reporting Services report and prints
it to a network printer using the System.Drawing and System.Drawing.Printing
namespaces in .Net 2.0. This method has...
|
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: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |