character arrays

If wanted to take a character array such as "Hello! Whats up?" and wanted to turn it into this: "hellowhatsup".

How would i go about doing that?
Also i would like to accept numbers as well.

1
2
3
4
5
6
7
8
9
10
11
12
  char initial_string [30] = "Hello! Whats up?",
       second_string [30];

  for (int i = 0; i < 30; i++)
  {
     if ( How do I get rid of spaces and punctuation )
     {
         second_string[i] = initial_string[i];
         second_string[i] = tolower(second_string[i]);
     }
  }


That is what I have been thinking so far. Any help would be greatly appreciated.
You could use isalpha or isalnum in the <ctype.h> library:

http://www.cplusplus.com/reference/cctype/isalnum/
http://www.cplusplus.com/reference/cctype/isalpha/

1
2
3
4
5
6
7
8
9
10
11
char initial_string[30] = "Hello! Whats up?", 
     second_string[30];

int j = 0;
for (int i = 0; i < 30; i++)
{
  if (isalpha(initial_string[i]))
  {
    second_string[j++] = tolower(initial_string[i]);
  }
}
Last edited on
Excellent! Thankyou
Topic archived. No new replies allowed.