0
#include<stdio.h>
#include<conio.h>
#include<string.h>
struct student
{
    int*ptr[23];
    char*name[12];//store address of character string

}s1;
void main()
{
    int roll=20;
    //char n='s';
    s1.ptr=&roll;//ERROR
    s1.name="zahid ali";//ERROR
    printf("roll no of student :%d\n",*s1.ptr);
    printf("name of student:%s\n",s1.name);
    getch();
}//plase coorect this error
5
Contributors
5
Replies
35
Views
3 Years
Discussion Span
Last Post by rustysynate
0

Your struct members are arrays of pointers, but you're treating them as if they were just pointers.

Note that you can't assign to arrays and even if you could the values that you're trying to assign them are plain pointers, not arrays of pointers.

0

IE, what sepp2k said. IE:

    #include <stdio.h>
    #include<string.h>
    struct student
    {
        int* ptr[23];
        char* name[12];//store address of character string
    }s1;
    int main(void)
    {
        int roll=20;
        s1.ptr[0]=&roll;//ERROR
        s1.name[0]="zahid ali";//ERROR
        printf("roll no of student :%d\n",s1.ptr[0]);
        printf("name of student:%s\n",s1.name[0]);
        getch();
        return 0;
    }
-1

I guess this should help.

    #include <stdio.h>
    #include<string.h>
    struct student
    {
    int* ptr[23];
    char* name[12];//store address of character string
    }s1;
    int main(void)
    {
    int roll=20;
    s1.ptr[0]=&roll;
    s1.name[0]="zahid ali";
    printf("roll no of student :%d\n",*(s1.ptr[0]));
    printf("name of student:%s\n",s1.name[0]);
    return 0;
    }
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.