When I compile this program, I keep getting this error
example4.c: In function ‘h’:
example4.c:36: error: assignment of read-only location
example4.c:37: error: assignment of read-only location
I think it has something to do with the pointer. how do i go about fixing this. does it have to do with constant pointers being pointed to constant pointers?
code
#include <stdio.h>
#include <string.h>
#include "example4.h"
int main()
{
Record value , *ptr;
ptr = &value;
value.x = 1;
strcpy(value.s, "XYZ");
f(ptr);
printf("\nValue of x %d", ptr -> x);
printf("\nValue of s %s", ptr->s);
return 0;
}
void f(Record *r)
{
r->x *= 10;
(*r).s[0] = 'A';
}
void g(Record r)
{
r.x *= 100;
r.s[0] = 'B';
}
void h(const Record r)
{
r.x *= 1000;
r.s[0] = 'C';
}