Q:

Reading 2-D string Array From File In C

I am new at C and trying to make a little program. 
Basically it's a program that takes elements name, group, period (Not scientifically correct) number from a text file. Then insert elements names to 2d string array (elmName in code), element numbers to 2d int array (elmNumber) and then print them as the periodic table.  
But when i try to run it, program takes the last element name it read and assigns it every element in 2d string array (elmName).
Here is the code : 
char* elmName[18][5];

int elmNumber[18][5];
//AtomNumber[Group][Period] 

int iGroupCount = 18;
int iPeriodCount = 5;

for(int i=0;i<iPeriodCount;i++){
    for(int j=0;j<iGroupCount;j++){
        elmNumber[j][i] = 0;
    }
}

printf("\n");

for(int i=0;i<iPeriodCount;i++){
    for(int j=0;j<iGroupCount;j++){
        printf("%d ", elmNumber[j][i]);
    }
    printf("\n");
}

int g,p,num;
//g = Group
//p = Period
//num = Atom no.

int tempNum;
char tempName[2];

for(int i=0;i<iPeriodCount;i++){
    for(int j=0;j<iGroupCount;j++){
//if there is not an element at this group and period name it '*'
            elmName[j][i] = "*";
    }
}

FILE *fs = fopen("element.txt" , "r");
while(!feof(fs)){
    fscanf(fs ,"%d\t%d\t%d\t%s\n" , &g , &p , &tempNum , tempName);
    printf("%d\t%d\t%d\t%s\n" , g , p , tempNum , tempName);
    if( elmName[g][p] == "*"){
    elmNumber[g][p] = tempNum;
    elmName[g][p] = tempName;

}
     //g = group No
     //p = period No    
}

fclose(fs);

And here is the text file it reads : 
0   0   1   H
17  0   2   He
0   1   3   Li
1   1   4   Be
12  1   5   B
13  1   6   C
14  1   7   N
15  1   8   O
16  1   9   F
17  1   10  Ne
0   2   11  Na
1   2   12  Mg
12  2   13  Al
13  2   14  Si
14  2   15  P
15  2   16  S
16  2   17  Cl

If you have a solution please help. :)

A:

Change this line char* elmName[18][5]; to char elmName[18][5][4];
assuming your strings won't have more than 3 characters(3 characters + 1 for NULL). This line creates a 3 dimensional character array. 
The [i,j]th element of this will be a character string which is what you would require in this case:
Also change this line : if( elmName[g][p] == "*") to if( strcmp(elmName[g][p], "*")==0) .This is because you cannot compare values  of arrays (string which is a character array) using equal operator .
Also change elmName[g][p] = tempName; to strcpy(elmName[g][p],tempName).
Don't forget to include string.h . You have to copy each character to the character array which is done by strcpy
Here is the corrected code:
#include<stdio.h>
#include<string.h>
int main()
{
    char elmName[18][5][4];

int elmNumber[18][5];
//AtomNumber[Group][Period] 

int iGroupCount = 18;
int iPeriodCount = 5;

for(int i=0;i<iPeriodCount;i++){
    for(int j=0;j<iGroupCount;j++){
        elmNumber[j][i] = 0;
    }
}

printf("\n");

for(int i=0;i<iPeriodCount;i++){
    for(int j=0;j<iGroupCount;j++){
        printf("%d ", elmNumber[j][i]);
    }
    printf("\n");
}

int g,p,num;
//g = Group
//p = Period
//num = Atom no.

int tempNum;
char tempName[2];

for(int i=0;i<iPeriodCount;i++){
    for(int j=0;j<iGroupCount;j++){
//if there is not an element at this group and period name it '*'
            strcpy(elmName[j][i] , "*");//This line has been changed
    }
}

FILE *fs = fopen("element.txt" , "r");
while(!feof(fs)){
    fscanf(fs ,"%d\t%d\t%d\t%s\n" , &g , &p , &tempNum , tempName);
    printf("%d\t%d\t%d\t%s\n" , g , p , tempNum , tempName);
    if( strcmp(elmName[g][p], "*")==0)//This line has been changed
    {
    elmNumber[g][p] = tempNum;
    strcpy(elmName[g][p], tempName);//This line has been changed

}
     //g = group No
     //p = period No    
}

fclose(fs);
//For viewing results
for(int i=0;i<18;++i)
    for(int j=0;j<5;++j)
        printf("%d %d %s\n",i,j,elmName[i][j]);
    return 0;
}

This is the ouput that I got when using your sample file
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0   0   1   H
17  0   2   He
0   1   3   Li
1   1   4   Be
12  1   5   B
13  1   6   C
14  1   7   N
15  1   8   O
16  1   9   F
17  1   10  Ne
0   2   11  Na
1   2   12  Mg
12  2   13  Al
13  2   14  Si
14  2   15  P
15  2   16  S
16  2   17  Cl
0 0 H
0 1 Li
0 2 Na
0 3 *
0 4 *
1 0 *
1 1 Be
1 2 Mg
1 3 *
1 4 *
2 0 *
2 1 *
2 2 *
2 3 *
2 4 *
3 0 *
3 1 *
3 2 *
3 3 *
3 4 *
4 0 *
4 1 *
4 2 *
4 3 *
4 4 *
5 0 *
5 1 *
5 2 *
5 3 *
5 4 *
6 0 *
6 1 *
6 2 *
6 3 *
6 4 *
7 0 *
7 1 *
7 2 *
7 3 *
7 4 *
8 0 *
8 1 *
8 2 *
8 3 *
8 4 *
9 0 *
9 1 *
9 2 *
9 3 *
9 4 *
10 0 *
10 1 *
10 2 *
10 3 *
10 4 *
11 0 *
11 1 *
11 2 *
11 3 *
11 4 *
12 0 *
12 1 B
12 2 Al
12 3 *
12 4 *
13 0 *
13 1 C
13 2 Si
13 3 *
13 4 *
14 0 *
14 1 N
14 2 P
14 3 *
14 4 *
15 0 *
15 1 O
15 2 S
15 3 *
15 4 *
16 0 *
16 1 F
16 2 Cl
16 3 *
16 4 *
17 0 He
17 1 Ne
17 2 *
17 3 *
17 4 *

You are getting the last added element as output because you are assigning address of string tempName to the 2d character array pointer elmName. In my suggested solution I have used static 3 dimensional character array if you wanted to use 2 dimensional array you have to assign dynamically allocated character array (string)  to it instead of a statically allocated variable in your case tempName 

