Periodic Table C Program.

Hey, I am happy to upload my first program on the internet. This program is written in C language. It is a program to find Atomic numbers of certain elements. Read the ‘Readme’ file to know how I made this program.

Download the source code and the text file here:-

Download periodic table project

For the execution of this program, all these files are required and should be saved in the same directory. If you have downloaded the source code open the bcpt.c file with a text editor. I have first declared three variables along with their appropriate data types , for the storage of all the elements of periodictable.txt, b , to store the element specified by the user, and a , to store the matched string after scanning the text file.

By specifying file pointer FILE *fp the text file periodictable.txt is opened in read mode.


I have also put up an ‘if’ check to notify the user if the text file does not exist in the main directory. If the file has been removed the program exits the execution.

When the file is open it gets scanned line by line until the End of file isn’t encountered and all of its data gets stored in the variable e. Meanwhile, we ask the user to enter an element and it gets scanned and the stored in variable b.


The string compare function strcmp() is used in order to compare the strings stored in variable e and variable b. If they match that line is returned to the main.

The while loop specifically helps strcmp() in comparing each and every line one at a time until the end of the file and of the comparison matches the index of that particular file is returned and stored in another variable b. Later this variable is displayed on to the terminal or cmd with printf() function.

If the variable doesn’t exist in the text file then the else part is executed and you can printf() that the element entered by the user does not exist. I have used a flag found for stating the true or false as per the existence of the file. The strcmpi() lets the user a freedom to enter the element in upper case and lower case.


       if(strcmpi(b,e)==0){     /*Compare string one by one*/
            printf("The atomic number of %s is %d .\n",b,a);
            printf("The input element does not exist.”);

This program can be used for lots of other things like finding the values of certain physical constants like gravitational constant ‘G’. Also, you can access lots of other kinds of data with this program, you just have to edit the text file and the source file according to your needs.
Execute on Windows :- Open Command Prompt and (Change to the bcpt.c file’s directory), type :

> gcc bcpt.c
> a/.out

Execute on Linux :- Open Terminal and type :

$ gcc bcpt.c
$ ./a.out



The Modern Periodic table is referred from Wikipedia. If you find any bugs or have any suggestion to this program comment below and let me know. Happy programming !






2 responses to “Periodic Table C Program.”

  1. Java Swing GUI- Chemical Properties of Elements | SHIRISH KADAM Avatar

    […] In one of my previous posts, I made a C program, which would find the atomic number of an element from a text file and display it. Here today I […]


  2. ramesh reddy Avatar
    ramesh reddy

    sir,please send c program to execute modern periodic table to my emai


Leave a Comment:

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: