error in strcpy function

help in that issue plz

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 <stdio.h>
# include "math.h"  
# include "stdlib.h"
# include "string.h"

int  main ()
{
	char text[1000],chartext[1000],numtext[1000];
	int result,a,b;
	printf ("     "" WELCOME ""\r\nEnter your Expression ^_^ \r\n");
	gets(text);
	for(  int i=0;i<20;i++)
	{
		if (text[i]=='+')
		{
			strcpy(chartext[i],text[i]);
		}
		if ((text[i]>=0)&&(text[i]<=9))
		{
			strcpy(numtext[i],text[i]);
		}
	}
	strcat(numtext,chartext);
	printf ("result is %d\r\n",numtext);
}

it gives that error
Error 3 error C2664: 'strcpy' : cannot convert parameter 1 from 'char' to 'char *'
Last edited on
strcpy expects a null-terminated string (char *) not a single character. See:
http://www.cplusplus.com/reference/clibrary/cstring/strcpy/

If you just want to copy a character, try assignment:
chartext[i] = text[i]

Note that you will have to manually null-terminate the resulting character arrays, if you intend to display them via printf. Also, use %s for strings.
Use strncat():

strncat(chartext,text,1);

[edit]
That is, to append a character to a string, use:
1
2
3
4
char c = '!';
char s[100] = "Hello world";

printf( "%s", strncat( s, &c, 1 ) );
Last edited on
Topic archived. No new replies allowed.