|
Write a function to check that a given string is a valid IP address. An IP address is of the form a.b.c.d where a,b,c,d are numbers in the range 0-255 without a leading zero. You are not allowed to use any string methods like split, indexof, parseInt etc, in C language
|
|
|
|
|
its actually quite easy, but :-
1) sounds like homework - DO YOUR OWN
2) I dont like 'Please give the correct ans' - people here give the best answer they know according to their experience & knowledge, and dont mislead/give deliberatly wrong answers, so I take offence to this
'g'
|
|
|
|
|
In C language there is nothing like IndexOF,ParseInt and splits..
you can use strstr to find '.' and atoi to convert strings to number
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
#include <regex.hpp>
int match(const char * what)
{
return(regex_match(what,"^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$")
}
That should impress your teacher...
|
|
|
|
|
The correct way to check IP4 addresses for validity is:
bool validate_addr(const char* ip)
{
return inet_addr(ip) != INADDR_NONE;
}
|
|
|
|
|
Yes, but it does not follow the requirements. inet_addr will accept any dot notation, so "4.003.002.0x10" will be valid. I think the purpose of the exercise is to lead gently to stuff like atoi(), format strings, and so on...
|
|
|
|
|
I agree on your answer - clever
|
|
|
|
|
|
Characterize and compare the performance of file I/O by implementing reading and writing of files through the following three methods:
· I/O through system calls read and write
· Memory mapped I/O through mmap
· Buffered I/O through read and write
You should implement a program that can either read or write blocks of a given size from a large file. The user should be able to specify the I/O method to use for reading and writing. For example, writing blocks of 1K through system calls (the first method above) may be done as follows:
iotest --method=syscall --blocksize=1024 --operation=write
Use your program to measure the read and write I/O performance achieved through the three methods for various block sizes. What can you deduce from your observations?
|
|
|
|
|
Happy to learn about your school assignment. Now get on with it...
|
|
|
|
|
Sorry my MIND is still searching for answer.. i think i have to fit google in my mind to search faster
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
That's the second site I've read that question on tonight.
|
|
|
|
|
|
javster87 wrote: Use your program to...
The operative word is YOUR.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Hello,
i need help with some C code.
lets say i have an array ..for example {1,3,2,5,10,11,8,7,9}
i need find the the largest part that gives me A[i] < A[i+1] < A[i+2]..
in this case its {2,5,10,11)
and the algorithm should return me the j that started this series of number (j=2)
what should i do?
i'd be glad if anyone can help me reaching the answer.
|
|
|
|
|
you again?
Farraj wrote: the largest part
define "largest part". is it the part holding the largest value; or having the most elements; or having the largest sum of elements; or...
whichever it is, reading the array sequentially will solve it; just calculate the current merrit, and remember the best so far.
|
|
|
|
|
I understand it as the longest sequence where a(i)<(a(i+1)<a(i+2) ...
<div="" class="signature">Watched code never compiles.
|
|
|
|
|
hi, thanks for ur reply
Farraj wrote: the largest part that gives me A[i] < A[i+1] < A[i+2]..
i mean the largest sequence of a[i] < a[i+1]..like 2 3 4 5
|
|
|
|
|
I guess you need to sort in ascending order.
You can either code any of the sorting algorithm.
Or
You can put the array into a vector container and then call the sort function.
|
|
|
|
|
And what is your doubt about (just a couple of loops would suffice, at first sight)?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
one loop is all it takes, this is an O(n) job.
|
|
|
|
|
Yes, I realize you may complete it with just one loop and pair of variables.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
so you did read the hint[^]
|
|
|
|
|
Of course.
Now, plz gimme codez!
(urgentz)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
bubble sort and binary search
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|