[Solved] Change the output format of a string [closed]

[ad_1] A little bit quick’n’dirty, but you should get the idea. public static void Main(string[] args) { Regex regex = new Regex(“(([_ ]*[a-z]+)_ ?)+([_ ]*[a-z]+)”); string str = “a_b_c_ _ _abc_ _ _ _abcd”; Match match = regex.Match(str); // 2 – because of specific regex construction for (int i = 2; i < match.Groups.Count; i++) … Read more

[Solved] what is the algorithm for function that check how many series in ascending order array have. and detect the longest series in c

[ad_1] #include <stdio.h> int main(){ int arr[] = {12,3,4,23,5,46,5,6,7,78,67,68,134,45,46,47,67,11,23,18,-3}; int count = 21; int i; int pos=0, len=0; for(i=0;i<count-1;++i){//i<count-1-len int k; for(k=0;arr[i+k]<arr[i+k+1];++k) ; if(k>len){ len = k; pos = i; } i += k; } printf(“Longest series: “); for(i=pos;i<=pos+len;++i) printf(“%d “, arr[i]); printf(“\n”); return 0; } [ad_2] solved what is the algorithm for function that … Read more

[Solved] Returning pointer to array doesn’t give expected output in c [duplicate]

[ad_1] newarray is an automatic local variable. It will no longer exists once function return. Returning pointer to an automatic local variable invoke undefined behaviour and in this case nothing good can be expected. You can allocate memory diynamically and then return pointer to it int *newArray = malloc(sizeof(int)*size); 2 [ad_2] solved Returning pointer to … Read more

[Solved] how can I print ascii code value in c++ in this way?

[ad_1] You should use a string for your input (it’s c++, not c). Your for loop sums 32 characters, even if the user inputs a shorter string (the programm will read random values from memory). For conversion from int to char you can use stringstream. This results in #include <iostream> #include <string> #include <sstream> int … Read more

[Solved] C – Trouble calling a function

[ad_1] Here is a main() that calls base64_encode(): int main(void) { char data[] = “test”; char *encoded_data; size_t len; encoded_data = base64_encode(data, strlen(data), &len); printf(“%s (%zu) => %s (%zu)”, data, strlen(data), encoded_data, len); } Explanation char data[] contains your string to encode. You’ll need to pass it as an argument to base64_encode(). char *encoded_data is … Read more

[Solved] C++ what is the point of “const” keyword? [duplicate]

[ad_1] Non-exhaustive list of reasons: Software Engineering (SWE). SWE is not just programming, but programming with other people and over time. const allows to explicitly express an invariant, which lets you and others reason about the code. As the program becomes bigger, these invariants cannot be just memorized. That’s why encoding them in the programming … Read more

[Solved] Asp.net foreach loop [closed]

[ad_1] Let me explain what foreach actually does. It iterates over a collection of elements inside an IEnumerable, in order, without skipping anything, even if the current element has the value null. If you have an array with [5,2,24], the elements will be called in oder 5, 2, 24 and will stop after that. 5 … Read more

[Solved] How do I write the copy Constructor for Composition? [closed]

[ad_1] Try like this: #include <string> #include <iostream> class Pulley{ private: int noOfTeeth; public: Pulley(int teeth = 0); void show(); }; Pulley::Pulley(int teeth) : noOfTeeth(teeth) { std::cout << “Pulley constructor called!”; } void Pulley::show() { std::cout << “\n\nNo of Teeths of Pulley: ” << noOfTeeth; } class GearBox{ private: std::string transmission; Pulley p; public: GearBox(std::string … Read more

[Solved] Array of an object of a class [closed]

[ad_1] It depends on how your class looks but this would be a simple example: #include <iostream> using namespace std; class MyClass { int x; public: void setX(int i) { x = i; } int getX() { return x; } }; int main() { MyClass test[4]; int i; for(i=0; i < 4; i++) test[i].setX(i); ` … Read more

[Solved] C char array storing a variable [closed]

[ad_1] The file stdout, which is what printf writes to, is by default line buffered. That means everything you write to it is buffered, i.e. stored in memory, and is flushed (and actually printed) when you print a newline. 2 [ad_2] solved C char array storing a variable [closed]

[Solved] How to change a char to ASCII form?

[ad_1] Buff_Y[2] = (Y / 100) + 0x30; Buff_Y[1] = (Y / 10) % 10+0x30; Buff_Y[0] = (Y % 10) + 0x30; This is all good. If you print those three bytes, you will see that they contain the right values. SBUF = *Buff_Y; This, however, indicates confusion. *Buff_Y is equivalent to Buff_Y[0]. That is … Read more

[Solved] Dots in printf in C++

[ad_1] If you are puzzled about the dots here is what they are: %.1lf is the format specification for precision. This is requesting one digit after the decimal point in the printf output. The 1. and 2. in (a*1.+b)/2. mean that those literals are double (as opposed to 1 that would be int and 1.f … Read more

[Solved] why web.config has predefined tags? [closed]

[ad_1] Web.Config itself is written in XML format right? Yes, but in addition to that it has an XML schema associated and the Configuration class which is responsible to read values from this XML file verifies that the schema is being respected. You should make the distinction between well formed XML and valid XML according … Read more