How to print string with structure
Code:
#include<stdio.h>
struct account
{
char name;
int number;
};
int main()
{
struct account profile;
profile.name = 'j';
profile.number = 99;
printf(" name %c \n",profile.name);
printf(" name %d \n",profile.number);
return 0;
}
name j
name 99
I want to print string "jack"
Code:
#include<stdio.h>
struct account
{
char name[5];
int number;
};
int main()
{
struct account profile;
profile.number = 99;
profile.name[5] = "jack";
unsigned int i;
for(i =0; i < 5; i++);
printf(" name %s \n",profile.name[i]);
printf(" name %d \n",profile.number);
return 0;
}
assignment makes integer from pointer without a cast [-Wint-conversion]
profile.name[5] = "jack";