Archive for Problems I encountered and solved

How to check decimal separator and number group separator for your system?

            string numberDecimalSeparator = System.Globalization.CultureInfo.CurrentUICulture.NumberFormat.NumberDecimalSeparator;
            string numberGroupSeparator = System.Globalization.CultureInfo.CurrentUICulture.NumberFormat.NumberGroupSeparator;

            Console.WriteLine("Ondalik ayraciniz:{0}", numberDecimalSeparator);
            Console.WriteLine("Sayi grup ayraciniz:{0}", numberGroupSeparator);

Run-Time check failure #2 – Stack around the variable ‘str’ was corrupted.

This error’s source is there is a situation you want to read a place that is outside of array’s bounds.
As mentioned in above link, &str[2][1000] points to str[3] which does not exist.

Can we change value pointed by the constant pointer?


Author: StackOverflow1453
Date: 9/2/2013 3:54:34 PM
Description: Can we change value pointed by the constant pointer?


#include <stdio.h>

int main(void){

	char *s1="Ankara";
	char s2[]="Bursa";


	char *strPtr ="Hello" ;

	Defines strPtr a pointer to char pointing to a string literal "Hello" -- 
	the effective type of this pointer is const char *. 
	No modification allowed through strPtr to the pointee (invokes UB if you try to do so). 
	This is a backward compatibility feature for older C code. 
	This convention is deprecated in C++0x.

	//*s1[3]='0';  //YOU CAN NOT DO THIS!




Visual Studio 2012 Error: “no exports were found that match the constraint contract name” How to solve?

This morning I faced a problem while opening my Visual Studio solution and when I tried to run it. It said “no exports were found that match the constraint contract name”

Solution is:

This issue can be resolved by deleting or clearing all the folders and files from %AppData%\..\Local\Microsoft\VisualStudio\11.0\ComponentModelCache

This actually clears visual studio component model cache.

In windows 7 machines, path is different. When you type %appdata% n RUN command it opens the folder C:\Users\\AppData\Roaming

click ‘up’ button to navigate to parent folder and select the folder ‘Local’

final path : C:\Users\\AppData\Local\Microsoft\VisualStudio\11.0\ComponentModelCache

C initialization of a normal array with one default value

int array[100] = {-1};

Expecting it to be full with -1’s but its not, only first value is -1 and the rest are 0’s .

int array[100] = {0};

Works just fine and sets each element to 0.

It seems that if you want to initialize all elements other than “0”, you have to use a for loop. No other way.

for (i = 0; i < 100; ++i){
  array[i] = -1;

How to make item template with Visual Studio 2012?

When you create a file, if you want to insert automatically date, time and whatever you want to see every time on the header file, you have to follow this. if you want to add a time inserted automatically, you have to insert as $time$ as stated below. There are lots of parameters in below link. Happy programming…

IMPORTANT NOTE: Do not forget to change

  1. Set the ReplaceParameters attribute of the element to true!!!!! Otherwise it wont work…

How to make a random sized array with random elements in C with MS Visual Studio? (C90 compliant compiler)

In C, declaration of all locals before doing code statements required.
In C89, declarations must precede statements within a block; in C99 and later (and in C++) they can be mixed.
Visual Studio uses old one. This compiler doesn’t accept mixed declarations and code. It is enforcing C89/C90 rules, which don’t permit declarations to follow statements within a block.

Below is the random array generation code.
I do not know what malloc is so I copy and pasted it from internet.
Care must be taken to put srand before rand.
(Without a call to srand(), rand() behaves as if you had called srand(1), and generates the same sequence each time.)

	int size;
	int *array2;	

	srand( time( NULL ) ); 					//This must be declared before rand() otherwise rand will get seed as 1 (srand(1)) everytime
	size=(rand()%100)+1;					// size can be in the range [1 to 100]

	/*to make a random array you have to use below creature! I have no idea what "malloc" is. I found this in internet!*/

	array2 = (int*) malloc(sizeof(int)*size);

	for(i=0;i<size;i++)     				//fill the array with random numbers