0

I have an array called names .
The element to remove is Stephanie Conley

char names[30][50]={"Henry Bush","Stephanie Conley","Ronald Boon","Aura Henry","Larry Knox"};

main(){
int i,indice = 1; // 1 = Stephanie Conley
int n=4; // total number of elements in the array

 for (i=indice;i<=n-1;i++)
   names[i]=names[i+1];

}

Error : assignment to expression with array type

Mohamed
  • 1
  • 1
  • 1
    `char names[30][50]` change to `const char* names[30]`. Or if you actually want to copy the data round, use strcpy. – Lundin Nov 22 '18 at 08:04
  • The C language doesn't support assignment of arrays. And you can't remove any member of an array. You should replace the member of the array with the successor. You should also check if you need a two-dimensional array. Try to use an array of pointers to char arrays. – harper Nov 22 '18 at 08:04
  • An array of arrays is still an array. :) – Sourav Ghosh Nov 22 '18 at 08:04
  • const char* names[30] works but can i do it without pointer ? – Mohamed Nov 22 '18 at 08:06
  • @Lundin I don't think it should be closed. First, it is not a complete duplicate of the other question, and, second, none of the answers truly explain why you cannot assign an array, but happily take its address. And I think that is the trap the OP (and many others) fall into. – GermanNerd Nov 22 '18 at 08:37
  • @GermanNerd Feel free to suggest a better duplicate. Though I think using canonical dupes that roughly answer the question is fine, when the OP is asking for the contents of a beginner-level C programming book. We probably have hundreds of duplicates regarding problems when assigning strings with the `=` operator. – Lundin Nov 22 '18 at 08:41
  • I was actually looking for a solution without using pointer, anyway that work ` for (i=indice;i<=n-1;i++){ j=0; l2 = strlen(names[i]); l1 = strlen(names[i+1]); if (l1>l2) l=l1; else l=l2; while (j – Mohamed Nov 22 '18 at 09:34

0 Answers0