[Solved] How to convert IPv4 address to decimal

It turns out that Winsock 2 provides the inet_addr() function, which simply returns the equivalent decimal value for the address. #include <stdio.h> #include <winsock2.h> int main(void) { char* pAddr = “192.168.0.1”; unsigned long value = inet_addr(pAddr); if (value == INADDR_NONE) printf(“Invalid format of IP address”); else printf(“Decimal representation of %s is: %lu”, pAddr, value); return … Read more

[Solved] Why this code is compiling? [closed]

You could have easily search for the reason in the documentation. From MSDN: By using the params keyword, you can specify a method parameter that takes a variable number of arguments. You can send a comma-separated list of arguments of the type specified in the parameter declaration or an array of arguments of the specified … Read more

[Solved] Put Space between numbers in C# [closed]

string num = “42339”; string result = String.Join(” “, num.Select(c=>c)); EDIT: This part is just for fun, I collected some alternatives from comments and also added a few string numstr = “42339”; string result = String.Join(” “, numstr.Select(c => c)); string result = String.Join(” “, (IEnumerable<char>) numstr); string result = String.Join(” “, numstr.AsEnumerable()); string result … Read more

[Solved] C++ vulnerability issue with pointers

a=b; After this assignment a points to the same location as b (“Secure Coding”). You have lost any reference to the initial location pointed by a, so essentially “Insecure Coding” is garbage that cannot be freed. Another issue is that you are freeing the same pointer twice. After the first free you no longer own … Read more

[Solved] Loop through xml [closed]

You have to have a eMail class. (you can change the name in the code sample) it should work. XDocument xdoc = new XDocument(); xdoc = XDocument.Load(fileName); var songlist = from c in xdoc.Element(“Result”).Elements(“email”) select new eMail{ ID = c.Element(“ID”).Value, Subject = c.Element(“Subject”).Value }; solved Loop through xml [closed]

[Solved] How take the string between two symbols c#? [closed]

I’m not sure if this matches what you need but you could try: var myString = “!re=.id=2CB=name=xxname123=service=vpn=caller-id=”; var match = new Regex(@”\.id=(?<value>[^=]*)=”).Match(myString); var id = match.Groups[“value”].Value; I haven’t tested this for specific syntax, but that should get you just that captured string. You can modify that to iterate across a MatchCollection if you need to … Read more

[Solved] C++ is not Giving Expected output [closed]

You are using setData on object of class A , but calling compare on object of class B. Use b in both case. int main() { A a; B b; //int c; clrscr(); b.setData(25,9); cout<<“answer: “<<b.compare(); getch(); return 0; } also change signature of main method. 3 solved C++ is not Giving Expected output [closed]

[Solved] A function to print copies of a character [closed]

“How to write a function which gets a character and the number of copies as function arguments?” As mentioned, you can implement your printSplitter() function simply as std::string printSplitter (int N, char C) { return std::string(N,C); } See the reference documentation of std::string constructor‘s (2). So you probably want to have something simple like this … Read more

[Solved] Any other way to write a loop for multiplication table to take run time values? [closed]

This is not a Python For loop In python,you can use the Range function to have a nice multiplication table. def table_choice(my_choice=None): for a in range(10): if my_choice != None: print(‘{0} x {1} = {2}’.format(my_choice, a, my_choice * a)) else: for b in range(10): print(‘{0} x {1} = {2}’.format(a, b, a * b)) table_choice(my_choice = … Read more

[Solved] C++ Multi Switch and Break?

A break statement only breaks the closest switch/loop that it is called in. In your example, the break statements of the inner switch would only break out of the inner switch, execution would return to case 0 of the other switch. And then, since that case 0 does not have a break of its own, … Read more

[Solved] How to call a function in C++

I donĀ“t know if it could be for not having a “main” function Well, yes, that’s kind of a problem. Each program must have a main() function. Where else would the execution start from? how can i call the function “RegistrarUnaInclusion” to make it work? RegistrarUnaInclusion is a member function of class ListaCircular. Therefore, you … Read more