I want to write a code that sort a cstring and put all the correct character into a new cstring,
Here is my Code.

#include<iostream>
#include<cstring>
#include<cctype>
using namespace std;
int main()
{
  char array[200]={"How Are U?"};
  char array1[200];
  int n=0;
  for(int i=0;array[i]!='\0';i++)
{
   if(islower(array[i])||array[i]==' ')
     {
     strcpy(array1[n],array[i]);
     n++;
}
}
}

but I get this when I try to compile
“invalid conversion from 'char' to 'char*'”
What should i do to make this right? Thanks!

What are the types of one, two and three in this example?

char myString[20];

??? one   = myString;
??? two   = myString[2];
??? three = &myString[2];

strcpy takes a char* as first and second argument.

This function strcpy() expects c-strings not characters

strcpy(array1[n],array);

array1[n] and array are characters.

>>strcpy(array1[n],array);

Just use simple assignment array1[n] = array[i];

Why is it when I try to get an OP to think about the problem himself that other people just tend to give away the answer - he's just going to do what you say now without actually understanding what's happening.

>>strcpy(array1[n],array);

Just use simple assignment array1[n] = array[i];

But array1 would not be a cstring, I want to copy the desired element from array without changing anything of array1

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.