Connecting Tech Pros Worldwide Forums | Help | Site Map

Help with pointers

Newbie
 
Join Date: Nov 2006
Posts: 14
#1: Nov 14 '06
I can't figure out how to fix this,can any one help me please:


void main()
{
char string[20];
char *aString=string;
function(aString);
}
void function(char *name)
{
cout << "enter name";
cin >> *name;
cout << name;
}

Banfa's Avatar
AdministratorVoR
 
Join Date: Feb 2006
Location: South West UK
Posts: 6,180
#2: Nov 15 '06

re: Help with pointers


cin >> name;
Newbie
 
Join Date: Oct 2006
Posts: 1
#3: Nov 15 '06

re: Help with pointers


#include <iostream.h>
#include <stdlib.h>
i think like this your program should be



void function(char *name)
{
cout << "enter name";
cin >> name;
cout << name;
}


void main()
{
char string[20];
char *aString=string;
function(aString);
}
Banfa's Avatar
AdministratorVoR
 
Join Date: Feb 2006
Location: South West UK
Posts: 6,180
#4: Nov 15 '06

re: Help with pointers


Actually

void main()

is wrong to an will invoke undefined behaviour, it should be

int main()

and you should return a value from main
Reply