All I am trying to do here is change the first letter to a capital. While I'm in the function makefirstcapital the first letter is changed, the odd part comes when I go back to main firstname is bumped to secondname, and firstname has random stuff in it.
Code:
#include <iostream>
#include <stdlib.h>
#include <string.h>
void makefirstcapital(char*);
using namespace std;
int main(int argc, char *argv[])
{
char first[20],second[20];
cout<<"First name:";
cin>>first;
cout<<endl<<"Second name:";
cin>>second;
makefirstcapital(first);
cout<<endl<<first;
cout<<endl;system("PAUSE");
return 0;
}
void makefirstcapital(char *name)
{
char switchchar[1];
switchchar[0]=name[0];
strupr(switchchar);
name[0]=switchchar[0];
}
Am I passing the pointer wrong? I appologize if this is a noobish question.