I am writing simple program in visual studio c++ 2012. I take some input dynamically. While printing on console int values it works fine but printing char *somevariable it stops and give error program.exe has stopped working.
my program is like
#include <stdlib.h>
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
int choice;
//char *userName;
static char* password;
static char* firstname;
static char* lastname;
static char* username;
char* name;
printf("\n 1.Login");
printf("\n 2.register");
printf("\nEnter choice");
scanf("%d", &choice);
printf("\n%d", choice);
switch (choice) {
case 1:
printf("\n Enter username :");
scanf("%s", &username);
printf("\n Enter username :");
scanf("%s", &password);
break;
case 2:
printf("\n Enter Firstname :");
scanf("%s", &firstname);
printf("\n Enter lastname :");
scanf("%s", &lastname);
printf("\n Enter username :");
scanf("%s", &username);
printf("\n Enter username :");
scanf("%s", &password);
printf("\n");
//name = "sdfjsdjksdhfjjksdjfh";
printf("%s", password);
break;
default:
printf("\n Wrong Choice Entered..");
break;
}
getchar();
return 0;
}