C Programming Structures within Structures

Hello,

Can someone tell me why I am getting Lvalue required error in the getsmtdata function at the lines where I am trying to set the Attribute name ?

struct Attribute
{
char id;
char name[40];
char status[2];
char value;
char worst;
char raw[6];
};

struct SmartData
{
struct Attribute Attributes[30];
char ExecutionStatus;
};

void getdsmtdata(struct SmartData *smtdata, char *fn)
//This function opens the smtdata file and extracts the attribute data.
{

FILE *input;
char junk;
int count;

printf("in getdinfo(), fn = %s", fn);
//ch = getch();
if((input = fopen(fn, "rb")) != NULL)
	{
		fseek(input, 2, SEEK_SET);

	  for(count = 0; count<30; count++)
	  {
			junk = fgetc(input);
			switch(junk)
			{
				case 1:
					smtdata->Attributes[count].name = "Read Error Rate";
					break;
				case 2:
					smtdata->Attributes[count].name = "Throughput Performance";
					break;
				case 3:
					smtdata->Attributes[count].name = "Spin Up Time";
					break;
				case 4:
					smtdata->Attributes[count].name = "Start/Stop Count";
					break;
				case 5:
					smtdata->Attributes[count].name = "Reallocated Sector Count";
					break;
				case 7:
					smtdata->Attributes[count].name = "Seek Error Rate";
					break;
				case 8:
					smtdata->Attributes[count].name = "Seek Time Performance";
					break;
				case 9:
					smtdata->Attributes[count].name = "Power On Hours";
					break;
				case 10:
					smtdata->Attributes[count].name = "Spin Retry Count";
					break;
				case 12:
					smtdata->Attributes[count].name = "Power Cycle Count";
					break;
				case 191:
					smtdata->Attributes[count].name = "Shock Sense Count";
					break;
				case 192:
					smtdata->Attributes[count].name = "Emergency Retract Count";
					break;
				case 193:
					smtdata->Attributes[count].name = "Load Cycle Count";
					break;
				case 194:
					smtdata->Attributes[count].name = "Temperature";
					break;
				case 196:
					smtdata->Attributes[count].name = "Reallocated Sector Event";
					break;
				case 197:
					smtdata->Attributes[count].name = "Pending Sector Count";
					break;
				case 198:
					smtdata->Attributes[count].name = "Offline Scan Uncorrectable";
					break;
				case 199:
					smtdata->Attributes[count].name = "CRC Error Count";
					break;
				case 220:
					smtdata->Attributes[count].name = "Disk Shift";
					break;
				case 222:
					smtdata->Attributes[count].name = "Loaded Hours";
					break;
				case 223:
					smtdata->Attributes[count].name = "Load Retry Count";
					break;
				case 224:
					smtdata->Attributes[count].name = "Load Friction";
					break;
				case 226:
					smtdata->Attributes[count].name = "Load In Time";
					break;
				case 240:
					smtdata->Attributes[count].name = "Write Head";
					break;
				case 254:
					smtdata->Attributes[count].name = "Free Fall Sensor Event";
					break;
				default:
					smtdata->Attributes[count].name = "Unknown";
					break;
			}//end switch statement

			smtdata->Attributes[count].id = junk;
			smtdata->Attributes[count].status[1] = fgetc(input);
			smtdata->Attributes[count].status[0] = fgetc(input);
			smtdata->Attributes[count].value = fgetc(input);
			smtdata->Attributes[count].worst = fgetc(input);
			smtdata->Attributes[count].raw[5] = fgetc(input);
			smtdata->Attributes[count].raw[4] = fgetc(input);
			smtdata->Attributes[count].raw[3] = fgetc(input);
			smtdata->Attributes[count].raw[2] = fgetc(input);
			smtdata->Attributes[count].raw[1] = fgetc(input);
			smtdata->Attributes[count].raw[0] = fgetc(input);
			junk = fgetc(input);
	  }//end for statement

	 fseek(input, 363, SEEK_SET)
	 smtdata->ExecutionStatus = fgetc(input);
	}
	 fclose(input);
	 input = NULL;

}

void main(int argc, char *argv[])
{

struct SmartData smtdata1, smtdata2;
			
getsmtdata(&smtdata1, "smtdata1.buf");
			
}//end main

Open in new window

LVL 1
Elena QuinnAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

evilrixSenior Software Engineer (Avast)Commented:
Try changing

void getdsmtdata(struct SmartData *smtdata, char *fn)


to be

void getdsmtdata(struct SmartData *smtdata, char char *fn)

The string you are parsing as argument 2 is const (it's a string literal)
0
Fabrice LambertFabrice LambertCommented:
smtdata->Attributes[count].name = "Read Error Rate";

Open in new window

In C, you can't assign a string directly like that. You need to use the strcpy function.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Elena QuinnAuthor Commented:
Thanks!! That was it.  I knew it was simple, my brain just couldn't get there today.
0
ozoCommented:
Becuse smtdata->Attributes[count].name is not an lvalue
It points to an lvalue, *(smtdata->Attributes[count].name) or smtdata->Attributes[count].name[0]
which you may be able to set with strncpy(smtdata->Attributes[count].name,"Read Error Rate",40);
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.