Hello..
Ive written this code which dont work, its jobis simply recieving names from the user in a structure [a] and delete a name that chosen by user, the compiler give me error flag in the line noticed bellow:)

#include <iostream.h>
#include <conio.h>

struct m{
       char n[15];       
       };
       

        

void main()          
{
   m a[50];             
    char name[15];            
     int i,size;
    cin>>size;       
    
   
    
    for(i=0;i<size;i++)
    {
          cout<<"entr elements";
    cin>>(a[i]).n;

}
cout<<"enter elment";
    cin>>name;
    
    
    for (int j=0;j<size;j++)
    {
    if((a[j]).n==name)
    for(int c=j; c<size;c++)
    ((a[c]).n)=((a[c+1]).n);            //this is The LINE
}
    for(i=0;i<size;i++)
    cout<<(a[i]).n<<endl;
    
getch();
}

Since you are using c-strings (character arrays) you do not get the luxury of using the <string> class overloaded == equality test.

But what you do get is a bunch of <cstring> library functions that will allow you to handle your character arrays with great ease:

#include<cstring>

//instead of this
if((a[j]).n==name)

//try this
if(strcmp(a[j].n, name))

Since you are using c-strings (character arrays) you do not get the luxury of using the <string> class overloaded == equality test.

But what you do get is a bunch of <cstring> library functions that will allow you to handle your character arrays with great ease:

#include<cstring>

//instead of this
if((a[j]).n==name)

//try this
if(strcmp(a[j].n, name))

Thank You Very much:)
I used your idea
even though it is right but it is not enough
the compiler still giving me An "Lvalue Required" Error

It simply means that the left value must be a single variable. You cannot have an equation equal to an equation. Try revising it a bit, and see if you can get it to work.

This is how I would write your block o' code:

#include<cstring>

for (int j=0;j<size;j++)
{
     if(strcmp(a[j].n, name)
    {
          strcpy(a[j].n, name);
          break;
    }
}

The code I provided you is untested. Please let me know where any additional errors are with line number.

Some rules to remember:

you can use all boolean logic when at the 'char' level (comparing 'chars' to 'chars') you can also assign chars to other chars.

You cannot directly use boolean logic to directly compare c-strings to other c-strings (arrays to arrays)

You can assign an array pointer to an array pointer of the appropriate type (assign an array to an array pointer) if the appropriate amount of memory has been allocated.

Only if you are using <string> class objects can you compare to 'string' type variables using == equality test, or assign one string to another using the = assignment operator, or 'concantinate' (add to) an existing string using the += 'accumulation' operator.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.