Passing char array to function

Hello everyone. This is a question to capitalize the input name. E.g.: paul adams TO Paul Adams..Kindly correct the code. I'm having trouble in passing char array to function and using 'null'. Thanks in advance.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include<bits/stdc++.h>
using namespace std;

char size(char name)
{
int i,c=0;
while(name[i]=='0')
{
    c+=1;
    i+=1;
}
return c;
}
char upper(char name,int c)
{
    int i;
    for(i=0;i<c;i++)
    {
        if(name[i]==' ')
        {
            name[i+1]=name[i+1]-32
        }
    }
return name;
}
int main()
{
char name[25];
cout<<"Enter your name";
gets(name);//inputting string along with spaces
name[0]=name[0]-32;//converting to uppercase wrt ascii values. a=97 A=65. difference=32
size(name);
upper(name,c);
cout<<name;
return 0;
}
Last edited on
void uppercstring(char*cp)
{
if(cp == null) //complain about it
else //for ... strlen(cp) ... upper case it etc.
it looks like it wants camel case; for that it is
upper case first letter, find space, upper case letter after space.
if you support multiple spaces, like bob du bleaux you need to do that space hunt/ next letter thingy in a loop.
}
you are not using pointers, so checking for null is doing much here.
its a good idea to allocate c-strings as zero filled.
char name[25] = {0}; //ensure end of string markers are in place. name is safe to use in c-string functions now, if you choose to do so, or you can print it safely now, etc.
Last edited on
Topic archived. No new replies allowed.