Error

Hi,

Getting error when trying to compile

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
  #include <stdio.h>
#include <ctype.h>
#include <string>


using namespace std;

void to_lower(const char*s);

{

   for (*s; ++s) {

   *s = (tolower(s));              // make lower
   
 }


}


int main()

{

char p;

while (cin>>p) { to_lower (p); }

return 0;

}
Last edited on
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
#include <iostream>
#include <cctype>
#include <string>

void to_lower( char* s )
{
    if( s != nullptr )
        for( ; *s ; ++s ) *s = std::tolower( *s ) ;
}

std::string to_lower( std::string s )
{
    for( char& c : s ) c = std::tolower(c) ;
    return s ;
}

int main()
{
    char cstr[] = "HELLO WORLD!\n" ;
    to_lower(cstr) ;
    std::cout << cstr ;

    const std::string str = "HELLO AGAIN!\n" ;
    std::cout << to_lower(str) ;
}

http://coliru.stacked-crooked.com/a/52288a54ba6b9e05
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

 #include <stdio.h>
#include <ctype.h>
#include <string>


void to_lower( char*s);

{

   for (; *s; ++s) {

   *s = (tolower(*s));              // make lower
   
 }


void test(const string& ss)	
{
	string s = ss;	
	cout << s << '\n';
	char* p = &s[0];	
	to_lower(p);
	cout << p << '\n';
}

int main()
{
	test("Hello, World!");
    
	string s;	
	while (cin>>s && s!="quit")	
		test(s);
}
Last edited on
Topic archived. No new replies allowed.