0

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!

4
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by ntgsx92
0

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.

0

This function strcpy() expects c-strings not characters

strcpy(array1[n],array);

array1[n] and array are characters.

0

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.

0

>>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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.