here is a code sample
void something()
{
char c[100];
scanf("%s",c);
char c2[100]=c;
}
my problem is when i do this assignment an error says that i can't assign
char * "c" to char[] "c2";
how can i achieve this assignment?
char* means a pointer to a character. In C strings are an array of characters terminated by the null character.
We can convert a char to a string object in java by using the Character. toString() method.
Difference between char s[] and char *s in CThe s[] is an array, but *s is a pointer. For an example, if two declarations are like char s[20], and char *s respectively, then by using sizeof() we will get 20, and 4. The first one will be 20 as it is showing that there are 20 bytes of data.
Given a string str and a character ch, this article tells about how to append this character ch to this string str at the end. Use the strncat() function to append the character ch at the end of str. strncat() is a predefined function used for string handling.
You'll have to use strcpy()
(or similar):
...
char c2[100];
strcpy(c2, c);
You can't assign arrays using the =
operator.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With