-5
struct PhaseShiftPin {
    int _PSPpin_index;      //PSP = Phase Shift Pin
    int _PSPvalue;
    char _PSPname[512];
};
struct PhaseShiftPin *_PhaseShiftPin[500000];
int p3int = 0;
strcpy ( _PhaseShiftPin[i]->_PSPvalue, p3int );

The above code is just part of my full code. When I compiled my full program happened an error strcpy' makes pointer from integer without a cast which is at line

strcpy ( _PhaseShiftPin[i]->_PSPvalue, p3int );

I have referred to the post at here makes pointer from integer without a cast with strcpy after I tried to use strncpy and follow the method showed in the post I still fail in compilation.Hope you can guide me with my problem.Thanks.

Community
  • 1
  • 1
user2609443
  • 5
  • 1
  • 5

2 Answers2

2

strcpy is inappropriate for this problem. It takes two arguments. The first is a pointer to char, and the second is a pointer to const char. It then copies the string pointed to by the second pointer into the memory pointed to by the first.

In your case, you are not copying a string, you are copying an int. Your last line should be:

_PhaseShiftPin[i]->_PSPvalue = p3int;

However, the C99 standard reserves identifiers that begin with an underscore ('_') followed by an uppercase letter or another underscore for the implementation. Therefore you must not name your identifiers this way.

ruds
  • 786
  • 4
  • 8
1

If you look at the definition of strcpy you can see

char *strcpy(char *dest, const char *src);

But your _PhaseShiftPin[i]->_PSPvalue is an integer and p3int also.

you can use memcpy

void *memcpy(void *dest, const void *src, size_t n);

strcpy ( &(_PhaseShiftPin[i]->_PSPvalue), &(p3int), sizeof(p3int) );

or simply as said in a comment

_PhaseShiftPin[i]->_PSPvalue =  p3int;

if you try to copy p3int into _PhaseShiftPin[i]->_PSPvalue

Alexis
  • 2,149
  • 2
  • 25
  • 39