V
venu reddy
Hi all,
I wrote an example code like this. I am getting error as " conversion
to non-scalar type requested error". help me!!.
#include<string.h>
typedef struct
{
int val;
char data[10];
}xyz;
main()
{
xyz a={10,"abcdefg"};
int i=0;
char data[20]={0};//={1,2,5,'c'};
void *ptr=data;
ptr=memcpy(data,&a,sizeof(xyz));
printf("%s ptr=%u data= %u \n",data,ptr,data);
printf("val=%u data=%s\n",((xyz)data).val,(xyz)data.data);
printf("val=%u data=%s\n",(xyz*)ptr->val,(xyz*)ptr->data);
}
for the above progrmme i am getting errors like this (compiled in gcc)
structCharmap.c: In function `main':
structCharmap.c:22: error: conversion to non-scalar type requested
structCharmap.c:22: error: request for member `data' in something not
a structure or union
structCharmap.c:23: warning: dereferencing `void *' pointer
structCharmap.c:23: error: request for member `val' in something not a
structure or union
structCharmap.c:23: warning: dereferencing `void *' pointer
structCharmap.c:23: error: request for member `data' in something not
a structure or union
My intention is, to typecast char* data to the structure and getting
the data.
ThanQ,
venu
I wrote an example code like this. I am getting error as " conversion
to non-scalar type requested error". help me!!.
#include<string.h>
typedef struct
{
int val;
char data[10];
}xyz;
main()
{
xyz a={10,"abcdefg"};
int i=0;
char data[20]={0};//={1,2,5,'c'};
void *ptr=data;
ptr=memcpy(data,&a,sizeof(xyz));
printf("%s ptr=%u data= %u \n",data,ptr,data);
printf("val=%u data=%s\n",((xyz)data).val,(xyz)data.data);
printf("val=%u data=%s\n",(xyz*)ptr->val,(xyz*)ptr->data);
}
for the above progrmme i am getting errors like this (compiled in gcc)
structCharmap.c: In function `main':
structCharmap.c:22: error: conversion to non-scalar type requested
structCharmap.c:22: error: request for member `data' in something not
a structure or union
structCharmap.c:23: warning: dereferencing `void *' pointer
structCharmap.c:23: error: request for member `val' in something not a
structure or union
structCharmap.c:23: warning: dereferencing `void *' pointer
structCharmap.c:23: error: request for member `data' in something not
a structure or union
My intention is, to typecast char* data to the structure and getting
the data.
ThanQ,
venu