When i tried to make the structure members(res_name,res_loc) as char pointer, i am getting error. i don't know how to convert res_name[25] to pointer.plz help me in this
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX 10
struct resource
{
int res_type;
char res_name[25]; // i want to use this as char * res_name
char res_loc[30]; // if i give it in that way where should i initialize it and how to
//access it inside the function.plz tell me
int res_pri;
}res[MAX];
int store(int g_id,char *g_name,struct resource res[],int n);
main()
{
int g_id,i=0,choice,nor,j,status;
char *g_name;
g_name=(char *)malloc(sizeof(char) * (MAX+1));
printf("\nEnter the Following Data...\n");
printf("Enter g_id:");
scanf("%d",&g_id);
printf("\nEnter g_name:");
scanf("%s",g_name);
printf("\nEnter the resources...");
do
{
printf("\nEnter %d res_type:",i+1);
scanf("%d",&res[i].res_type);
printf("Enter %d res_name:",i+1);
scanf("%s",res[i].res_name);
printf("Enter %d res_location:",i+1);
scanf("%s",res[i].res_loc);
printf("Enter %d res_priority:",i+1);
scanf("%d",&res[i].res_pri);
printf("\nDo u want to add another resource?\n 1.Yes\n2.N0\n:");
scanf("%d",&choice);
i++;
}while(choice==1);
nor=i-1;
j=0;
printf("--------------------------------------------------------------------------------------------------");
printf("\n\nG_id:%d",g_id);
printf("\nG_Name:%s",g_name);
status=store(g_id,g_name,res,nor);
}
struct
{
int g_id;
char g_name[25];
struct resource res[];
}g;
void store(int g_id,char *g_name,struct resource res[],int n)
{
int i=0,j=0;
g.g_id=g_id;
strcpy(g.g_name,g_name);
while(i<=n)
{
g.res[i].res_type=res[i].res_type;
strcpy(g.res[i].res_name,res[i].res_name);
strcpy(g.res[i].res_loc,res[i].res_loc);
g.res[i].res_pri=res[i].res_pri;
i++;
}
printf("\nG.G_id:%d",g.g_id);
printf("\nG.G_Name:%s",g.g_name);
while(j<=n)
{
fprintf(fp,"\nResource %d\n",j+1);
printf("**************");
printf("\ngr.Res_Type:%d:",g.res[j].res_type);
printf("\ngr.Res_Name:%s",g.res[j].res_name);
printf("\ngr.Res_Location:%s",g.res[j].res_loc);
printf("\ngr.Res_Priority:%d:\n",g.res[j].res_pri);
j++;
}