0

Working with shared memory for the first time, my project is to have readers and writers access shared strings and modify or read them, etc. I know that malloc doesn't work but not sure how to attach a 2d string array to memory, i keep getting this from the compiler:

warning: assignment makes integer from pointer without a cast

    int array_id;                         // id for the shared memory segment
    char records[10][50];                // the shared memory segment array

    // attach the reader to the shared segment
    fread(&newrecord, sizeof(id_record), 1, id_file);
    array_id = newrecord.id;

    printf("%d\n", array_id);

    records[0][0] = (char**) shmat(array_id, (void*) 0, 0);
    if (records[0] == (void*)-1) {
            perror("Array Attachment Reader");
    }

arrayid is correct i've triple checked it don't bring it up.

thanks

2 Answers 2

4

You will need to attach the shared memory, but store the pointer:

char (*records)[10][50];   // Pointer to an array

records = shmat(array_id, (void *)0, 0);

if ((void *)records == (void *)-1) ...error...

strcpy((*records)[0], newrecord);

You were trying to change the address at which the records array is stored; C doesn't allow that.

Sign up to request clarification or add additional context in comments.

1 Comment

You could also just use char (*records)[50] and then strcpy(records[0], newrecord);.
1

Don't use like this because records[0][0] is of char type not (char**)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.