Unable to correct this

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

Unable to correct this

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

Learn something about the language and how it works before you post code like that here and ask for help. How are we to have a clue what is going on in your main program? Where are your function declarations? Include lines? Tabbing? Space between char*aString=string somewhere? Take a look at a standard C tutorial and you should be OK.

Reguards,

Tyler S. Breton

void main()

Should be

int main()
#include<iostream>
#include<string>

using namespace std;

string char_to_string(char source[]);


int main()
{    
    string full_name;
    char   first_name[20];
    char   last_name [20];
    
    cout << "\n\nEnter First Name: ";
    cin.getline(first_name, 20);
    
    cout << "\n\nEnter Last Name: ";
    cin.getline(last_name, 20);
    
    full_name  = char_to_string(first_name);
    full_name += " ";
    full_name += char_to_string(last_name);
    
    cout << "\n\n\nYour full name is: " << full_name;
    
    cout << "\n\nPress [ENTER] to continue... ";
    cin.get();
    
    return 0;
}

string char_to_string(char source[])
{
   int i=0;
   string temp;
   
   while(source[i]!=NULL)
   
      temp += source[i++];
      
   return temp;
}

with pointers:

#include<iostream>
#include<string>

using namespace std;


string char_to_string(char* source);

int main()
{    
    string full_name;
    char   first_name[20];
    char   last_name [20];
    
    cout << "\n\nEnter First Name: ";
    cin.getline(first_name, 20);
    
    cout << "\n\nEnter Last Name: ";
    cin.getline(last_name, 20);
    
    full_name =  char_to_string(first_name);
    full_name += " ";
    full_name += char_to_string(last_name);
    
    cout << "\n\n\nYour full name is: " << full_name;
    
    cout << "\n\nPress [ENTER] to continue... ";
    cin.get();
    
    return 0;
}

string char_to_string(char* source)
{
   string temp;
   
   while(*source != NULL)
   {
      temp += *source;
      source++;
   }
      
   return temp;
}

Unable to correct this

[b]int[/b] main()      // manutd is correct
{
char string[20];
char *aString=string;
function (aString);
}
void function(char *name)
{
cout<< "enter name";
cin >> name;       // name is already a pointer, remove *
cout << name;
}

And learn to format your code. It will help you as your programs become larger. Each line after a { should be indented about 4 spaces. The } is unindented those same 4:

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

using namespace std;

void function(char *name);

int main()
{
    char string[20];
    char *aString=string;
    function (aString);
    return 0;
}

void function(char *name)
{
    cout<< "enter name: ";
    //cin >> name;
    cin.get(name,19); // so you can get more than one word in your string
    cout << name;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.