Click here to Skip to main content
15,922,512 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
#include <stdio.h>
#include <stdlib.h>

int main()
{
    char* element[] = {"Hydrogen","Helium","Lithium","Beryllium","Boron","Carbon","Nitrogen","Oxygen","Fluorine","Neon"};

	char j[2] = element[0];
	printf("%c\n",j[0]);

    return 0;
}


What I have tried:

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

int main()
{
    char* element[] = {"Hydrogen","Helium","Lithium","Beryllium","Boron","Carbon","Nitrogen","Oxygen","Fluorine","Neon"};

	char j[] = element[0];
	printf("%c\n",j[0]);

    return 0;
}
Posted
Updated 25-Mar-17 3:58am

Try this:
int main()
    {
    char* element[] = {"Hydrogen", "Helium", "Lithium", "Beryllium", "Boron", "Carbon", "Nitrogen", "Oxygen", "Fluorine", "Neon"};
    char* j;
    j = element[0];
    printf("%c\n",j[0]);
    return 0;
    }
element is an array of pointers to character.
So to access an element of the array, you need a pointer to a character:
C++
char* j;
 
Share this answer
 
C
#include <stdio.h>

int main()
{
    char* element[] = {"Hydrogen","Helium","Lithium","Beryllium","Boron","Carbon","Nitrogen","Oxygen","Fluorine","Neon"};

  printf("%c\n",**element);

  return 0;
}

:-)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900