#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
hassje
0
Newbie Poster
Recommended Answers
Jump to PostYour 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.
Jump to PostIE, 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; }
All 5 Replies
hassje
0
Newbie Poster
sepp2k
378
Practically a Master Poster
rubberman
1,355
Nearly a Posting Virtuoso
Featured Poster
shashikumar s g
15
Light Poster
rustysynate
0
Newbie Poster
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.