Metie Metie - 2 months ago 14
C Question

How to refer to a character of a member of an array structure in c?

I tried but I got an integer where the character should have been. Thanks for your help. The problematic part is at the 13th line.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct y{
char name1[30];
char name2[30];
} y;

void x(y *array){
int i;
for (i=0;i<2;i++)
printf("%d",array[i].name1[0]); /*<- Why is this integer?*/

int main()
y array[2]={
{ "apple", "battle"},
{ "cup", "dog" },


return 0;


This is happening because you are using the type-specifier %d, which is used to print an int in the printf function, in order to print a character, you need to use the type-specifier %c.