Function to change char array string to lower case

This code ran well until i added in the ToLower function which is supposed to convert the char array string to lower case (based off ascii strategy -32). Can someone please help me correct this function so it converts string to lower case and doesn't get errors.


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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63

#include <iostream> 
#include <string> 
using namespace std; 

const int MAX = 81; //max char is sting is 80 
void ToLower(char s[]); 


int main(){ 

string y_n; 
bool go = true; 
char myarray [100][MAX]; //How can i make this allow an open ended amount of string entries? 
int inputcount = 0; 
int count = 0; 

cout << "Do you want to input a String? ('Yes' or 'No')" << ": "; 
cin >> y_n; 


do{ 
if((y_n == "no") || (y_n == "No")) 
go = false; 

else if (y_n == "yes" || y_n == "Yes") 
{ 
cout << "Please Enter String" << ": "; 
cin.ignore(); 
cin.getline(myarray[count], MAX, '\n'); 
count++; 
++inputcount; 

ToLower(myarray[count]); // function to make string lower case 


cout << "Do you want to input a String (Yes or No)" ; 
cin >> y_n; 
} 

else{ 
cout << "Please enter a valid response - Either 'Yes' or 'No':"; 
cin >> y_n; 
} 

}while (go); 

for(int z = 0; z < inputcount; z++) 
cout << "String # " << z << " equals : " << myarray[z] << endl; 

cout << endl << "There are a total of " << inputcount << " " << "inputs"; 

cout << endl; 

return 0; 

} 

void ToLower(char s[]){ 
for(int z = 0; s[z] != ’\0’; z++) 
if((s[z] >='A') && (s[z] <= 'Z')) 
s[z] += 32; 
}
you need to pass either a reference or a pointer to the function
like this
void ToLower(char *s)
Last edited on
Topic archived. No new replies allowed.