stackoverflow1453

Programming&&Games&&Life

Archive for Reference

Code a simple enum type

/*

Name:
Copyright: 
Author: StackOverflow1453
Date: 10/24/2013 2:18:07 PM
Description: Enumeration

*/
#include <stdio.h>

int main(void){

	enum colors{green, blue, black};
	enum colors color;

	color=black;

	printf("%d\n", color);

	color=color++;

	printf("%d", color);

	getch();

}

How to get full user input (containing spaces tabs newlines) using fgets? (scanf does not work in this situation)

/*

Name:
Copyright: 
Author: StackOverflow1453
Date: 8/20/2013 2:11:40 PM
Description:

*/
#include <stdio.h>

int main(void){

	//arr size is automatically 6 done by the compiler
	char arr[]="Dummy";
	//declare array one by one (You have to include '' otherwise it gives error while printing
	char myName[]={'S','t','a','c','k','o','v','e','r','f','l','o','w',''};
	char dum[80];

	printf("%s \n",arr);
	printf("%s \n",myName);
	
	printf("Enter a word: ");
	//scanf reads till it encounters space, newline or tab
	//No need to add & operator in front of array name because it is already an address
	scanf("%s", myName);
	printf("You entered %s\n", myName);
	
	/* clear stdin of any extra characters */
	fflush(stdin);

	//if you want to get a full line with spaces tabs or newlines
	//you have to use fgets

	printf("Enter a line with spaces, tabs...\n");
	fgets(dum, sizeof(dum), stdin);
	printf("You entered by using fgets : %s", dum);
	
	getch();


}

Nice maze generator…

http://www.xefer.com/maze-generator
http://www.xefer.com/2007/07/maze

Pixel Art Tutorial

Pixel Art Tutorial

How to be an indie game developer??

How to be an indie game developer??

Advices from the creator of Spelunky on finishing Projects

Advices from the creator of Spelunky on finishing Projects

What is the difference of Break and Return?

/*

Name:
Copyright: 
Author: StackOverflow1453
Date: 7/29/2013 9:46:05 AM
Description: Break and Return difference


*/
#include <stdio.h>

int main(void){
	int i;
	int array[52];

	//fill array
	for (i = 0; i < 52; i++)
	{
		array[i]=i*i;
	}
	//check if an element is equal to 16
	for (i = 0; i < 52; i++)
	{
		if (array[i]==16)
		{
			printf("%d",i);
			return; //If there was a "break" here, Ahmet is printed.
		}
	}
	//This printf is passed because there is "return" in upper "for" loop 
	printf("Ahmet");
}