|
-
Apr 18th, 2002, 03:12 PM
#1
Thread Starter
Hyperactive Member
Compare chatacter to another?
i feel like such an amature again... what i'm trying to accomplish is to find the preriods in an ip address.
Code:
#include<string.h>
#include<iostream.h>
#include<conio.h>
void main()
{
void return_class(char ip[]);
char ip[] = {"155.25.54.1"};
return_class(ip);
}
void return_class(char ip[])
{
int sLength;
char firstoctet[4];
// get string length
sLength = strlen(ip);
// loop character array retrieving all characters the
// preceed the first period character
for(int x = 0; x < sLength; x++)
if(ip[x] == ".")
cout<<"period"<<endl;
getch();
}
i've also try tried the strcmp() functioins but all i get is cannot covert from char to char*
Code:
if(strcmp(ip[x], ".") == 0)
no go there! how can i loop through a character array and compare that character with another?
Thank, (so frustrating, when its so simple in vb)
Regan
Last edited by MOHH; Apr 18th, 2002 at 03:28 PM.
-
Apr 18th, 2002, 05:15 PM
#2
Code:
char *s = ip;
for(int x = 0; x < sLength; x++)
if( *s== '.') cout<<"period"<<endl;
-
Apr 23rd, 2002, 08:47 AM
#3
The loop isn't endless merely 'pointer-less'
-
Apr 23rd, 2002, 09:40 AM
#4
alright, but you test the same character all the time...
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|