[Solved] Junk values in char* variable

Strings in C need to be NUL terminated. This means you need to add a zero value byte to the end of the string to indicate the end of the string. Because you have no indication of the end of the string when you view/print the value you are reading on past the end of … Read more

[Solved] Does (p+x)-x always result in p for pointer p and integer x in gcc linux x86-64 C++

Yes, for gcc5.x and later specifically, that specific expression is optimized very early to just p, even with optimization disabled, regardless of any possible runtime UB. This happens even with a static array and compile-time constant size. gcc -fsanitize=undefined doesn’t insert any instrumentation to look for it either. Also no warnings at -Wall -Wextra -Wpedantic … Read more

[Solved] C# Arrays in List printing to console in formatted way [closed]

Simplest solution if all arrays have same length: string rowFormat = “{0,15}|{1,3} {2,3}”; Console.WriteLine(rowFormat, “History”, “B”, “W”); Console.WriteLine(new String(‘=’, 25)); for(int i = 0; i < array1.Length; i++) Console.WriteLine(rowFormat, array1[i], array2[i], array3[i]); But I would suggest to use custom type for your data instead of keeping data in three arrays. E.g. (names according to your … Read more

[Solved] odds to the first and evens last

How about this solution #include<stdio.h> int main() { int i; int arr[]={ 2, 1 ,4 ,3 ,6 ,5 ,8 ,7 ,9}; int arr_size = sizeof(arr)/sizeof(arr[0]); int sorted[arr_size]; int sp = 0; for(i=0;i<arr_size;i++){ if(arr[i]&1){ sorted[sp++]=arr[i]; } } for(i=0;i<arr_size;i++){ if(!(arr[i]&1)){ sorted[sp++]=arr[i]; } } for(i=0;i< arr_size ;i++) printf(“%d “, sorted[i]); return 0; } the output is 1 3 … Read more

[Solved] How to apply XSLT transformations to XML file and produce another XML?

The following XSLT does what you need (except formatting): <?xml version=”1.0″ encoding=”utf-8″?> <xsl:stylesheet version=”1.0″ xmlns:xsl=”http://www.w3.org/1999/XSL/Transform” xmlns:msxsl=”urn:schemas-microsoft-com:xslt” exclude-result-prefixes=”msxsl” > <xsl:output method=”xml” indent=”yes” encoding=”iso-8859-1″/> <!– Copy all elements recursively –> <xsl:template match=”@* | node()”> <xsl:copy> <xsl:apply-templates select=”@* | node()”/> </xsl:copy> </xsl:template> <!– Copy this element with subelements –> <xsl:template match=”order”> <!– Save ID for queries –> <xsl:variable … Read more

[Solved] how to pass a class object as parameter

Yes it is possible to pass an object as a parameter. class list { //some functions }; list merge(const list& l1, const list& l2) { list mergedList; //logic to merge l1 and l2 and copy it to mergedList return mergedList; } int main() { list LL1; list LL2; list mergedList = merge(LL1, LL2); } 4 … Read more

[Solved] completing this code (c) if you can

Change this: Nodes_maker(count2,&currentnode); to this: Nodes_maker(count2, currentnode); and the error will go away. That is because the prototype of the function is Nodes_maker(int nums,Node *currentnode) and you have Node* currentnode;. However, you need to work on your logic. I mean you dynamically allocate memory, but you don’t return the pointer (your function returns void). Good … Read more

[Solved] How to convert char array into string for DateTime.Parse? [closed]

Consider this: var date = “11252017”; var arrDate = date.ToArray(); var strDate = arrDate[0] + arrDate[1] + “https://stackoverflow.com/” + arrDate[2] + arrDate[3] + “https://stackoverflow.com/” + arrDate[4] + arrDate[5] + arrDate[6] + arrDate[7]; // 98/25/2017 Notice that: ‘1’ + ‘1’ = 98* ⇒ char + char = int 98 + “https://stackoverflow.com/” = “98/” ⇒ int + … Read more

[Solved] Generate random string from list of string in C#? [closed]

Try this: class Program { static void Main(string[] args) { int myRandomIndex = 0; var myList = new List<string>(new[] { “a”, “b”, “c”, “d”, “e”, “f”, “g”, “h”, “i”, “j” }); var results = new List<string>(); var r = new Random(DateTime.Now.Millisecond); for (int ii = 0; ii < 4; ii++) { myRandomIndex = r.Next(myList.Count); results.Add(myList[myRandomIndex]); … Read more

[Solved] Constructor that takes 1 argument

If second argument is not required then you can pass any value as var menu = new Menu (dt.Rows[0][0].Tostring(),string.Empty); Or if the value of both is to be same then pass same parameter twice as you mentioned in comment var menu = new Menu (dt.Rows[0][0].Tostring(),dt.Rows[0][0].Tostring()); 4 solved Constructor that takes 1 argument

[Solved] Battery Status in winforms

I thing that what you want to do is this: private void BatteryStatus() { System.Management.ManagementClass wmi = new System.Management.ManagementClass(“Win32_Battery”); var allBatteries = wmi.GetInstances(); foreach (var battery in allBatteries) { int estimatedChargeRemaining = Convert.ToInt32(battery[“EstimatedChargeRemaining”]); label13.Text = “Remaining:” + ” ” + estimatedChargeRemaining + ” ” + “%”; } } No need for and if statment, the … Read more

[Solved] I am not able to understand the exact meaning of this code [closed]

From a collection of DataRows a Datarow row is selected in each instance of for each. The row[“Mins”] representing Mins column in that row which is get converted into Decimal. Then compared with DbNull.Value for null check. If the value is null then 0.0 is taken else the original value from expression Convert.ToDecimal(row[“Mins”]). Same logic … Read more

[Solved] Use colors from other file

As @NetMage mentioned, you need to make all Members of Culori public. Also you need to create an instance of your Culori class to access the members. var culori = new Culori(); var myColor = culori.DEFAULT_COLOR; Alternatively you could make all members of Culori static: public static Color DEFAULT_COLOR = ColorTranslator.FromHtml(“#FF0000”); Then you should be … Read more