SlideShare a Scribd company logo
This is a problem where the word ho olate a e adefro the sy ols of ele e ts o the
periodic table like-
"C", "H", "O", "C", "O", "La", "Te"
using the symbols Carbon, Hydrogen, Oxygen, Lanthanum and Tellurium. Cobalt can also be used for the
"Co" before "La". The word "banana" or "bananas" can be made with "Ba", "Na", "Na" and "S", but
not with "N" because there is no "A" or "An" on the periodic table. Trying to use Nitrogen "N" would
appear to fail when checking the rest of the word, but using Sodium "Na" would work for the rest. So
one gotto try any combination of 1 and 2 letter element symbols. In this C program, determine if a
lowercase word can be made with any combination of 1 or 2 letter element symbols.
The list of chemical elements will come from a text file named chemelements.txtin which the 4 lines of
the file will each contain 25 atomic symbols. Input the filename from the keyboard. Let theuser enter
words to check for from the keyboard. Assume correct input (spelling). Output "Yes" or "No" for each
word indicating if it can be made from the element symbols.
The program is as follows:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
/* convert the word to lower case */
voidtoLower(char word[]);
/* read elements names from the given file
* convert their name into lower cases */
intreadElements(char filename[], char names[100][3]);
/* check if the word starting from index (pos) can be formed
* by using the element names in then names arrray */
int search(char names[100][3], int count, char word[], intpos);
int main()
{
char filename[256];
char word[256];
char names[100][3]; /* element names*/
int count;
/* ask the user to enter the filename */
printf("Enter the file name: ");
scanf("%s", filename);
/* ask the user to enter the word to search */
printf("nEnter the word: ");
scanf("%s", word);
toLower(word);
/* read the element names from the file */
count = readElements(filename, names);
/* search */
if (search(names, count, word, 0) == 1) {
printf("Yesn");
} else {
printf("Non");
}
}
/* convert the word to lower case */
voidtoLower(char word[])
{
int i;
for (i = 0; word[i] != 0; i++) {
/* convert to lower case */
word[i] = tolower(word[i]);
}
}
/* readingthe elements names from the given file and
* convert their name into lower cases */
intreadElements(char filename[], char names[100][3])
{
int count = 0;
FILE *in = fopen(filename, "r");
if (in == NULL) {
printf("Error: could not read file %s.n", filename);
exit(-1);
}
/* read names one by one until the end of file */
while (fscanf(in, "%s", names[count]) == 1) {
toLower(names[count]);
count ++;
}
fclose(in);
return count;
}
/* Here it is checked that if the word starting from index (pos) can
*be formed by using the element names in then names arrray */
int search(char names[100][3], int count, char word[], intpos)
{
int i;
intlen = strlen(word);
if (pos == len) {
/* already the end of word, thus its true */
return 1;
}
/* check if the part is one character in word,
* if the remaining word can be generated with element names */
for (i = 0; i < count; i++) {
int k = strlen(names[i]);
if (k == 1 && word[pos] == names[i][0]) {
/* found a matched single character element name,
* check the rest part */
if (search(names, count, word, pos + 1)) {
return 1;
}
}
}
/* In the below section it is checked that if the part is two
*characters in word,if the remaining word can be generated with
element names */
if (pos + 1 <len) {
for (i = 0; i < count; i++) {
int k = strlen(names[i]);
if (k == 2 && word[pos] == names[i][0] && word[pos + 1] ==
names[i][1]) {
/* found a matched two characters element name, then
* check the rest part */
if (search(names, count, word, pos + 2)) {
return 1;
}
}
}
}
return 0;
}

More Related Content

What's hot

Lists
ListsLists
LIST IN PYTHON
LIST IN PYTHONLIST IN PYTHON
LIST IN PYTHON
vikram mahendra
 
Chapter 15 Lists
Chapter 15 ListsChapter 15 Lists
Chapter 15 Lists
Praveen M Jigajinni
 
List , tuples, dictionaries and regular expressions in python
List , tuples, dictionaries and regular expressions in pythonList , tuples, dictionaries and regular expressions in python
List , tuples, dictionaries and regular expressions in python
channa basava
 
List,tuple,dictionary
List,tuple,dictionaryList,tuple,dictionary
List,tuple,dictionary
nitamhaske
 
List in Python
List in PythonList in Python
List in Python
Siddique Ibrahim
 
Below is a given ArrayList class and Main class Your Dreams Our Mission/tuto...
Below is a given ArrayList class and Main class  Your Dreams Our Mission/tuto...Below is a given ArrayList class and Main class  Your Dreams Our Mission/tuto...
Below is a given ArrayList class and Main class Your Dreams Our Mission/tuto...
davidwarner122
 
Data type list_methods_in_python
Data type list_methods_in_pythonData type list_methods_in_python
Data type list_methods_in_python
deepalishinkar1
 
Python list
Python listPython list
Python list
Mohammed Sikander
 
Python :variable types
Python :variable typesPython :variable types
Python :variable types
S.M. Salaquzzaman
 
Java Week4(C) Notepad
Java Week4(C)   NotepadJava Week4(C)   Notepad
Java Week4(C) Notepad
Chaitanya Rajkumar Limmala
 
An Introduction to Tuple List Dictionary in Python
An Introduction to Tuple List Dictionary in PythonAn Introduction to Tuple List Dictionary in Python
An Introduction to Tuple List Dictionary in Python
yashar Aliabasi
 
An Introduction To Python - Lists, Part 2
An Introduction To Python - Lists, Part 2An Introduction To Python - Lists, Part 2
An Introduction To Python - Lists, Part 2
Blue Elephant Consulting
 
File handling in c language
File handling in c languageFile handling in c language
File handling in c language
Harish Gyanani
 
1. python
1. python1. python
1. python
PRASHANT OJHA
 
Billing Software By Harsh Mathur.
Billing Software By Harsh Mathur.Billing Software By Harsh Mathur.
Billing Software By Harsh Mathur.
Harsh Mathur
 
Python Lecture 11
Python Lecture 11Python Lecture 11
Python Lecture 11
Inzamam Baig
 
Pytho_tuples
Pytho_tuplesPytho_tuples
C language header files
C language header filesC language header files
C language header files
marar hina
 
Groovy
GroovyGroovy
Groovy
Vijay Shukla
 

What's hot (20)

Lists
ListsLists
Lists
 
LIST IN PYTHON
LIST IN PYTHONLIST IN PYTHON
LIST IN PYTHON
 
Chapter 15 Lists
Chapter 15 ListsChapter 15 Lists
Chapter 15 Lists
 
List , tuples, dictionaries and regular expressions in python
List , tuples, dictionaries and regular expressions in pythonList , tuples, dictionaries and regular expressions in python
List , tuples, dictionaries and regular expressions in python
 
List,tuple,dictionary
List,tuple,dictionaryList,tuple,dictionary
List,tuple,dictionary
 
List in Python
List in PythonList in Python
List in Python
 
Below is a given ArrayList class and Main class Your Dreams Our Mission/tuto...
Below is a given ArrayList class and Main class  Your Dreams Our Mission/tuto...Below is a given ArrayList class and Main class  Your Dreams Our Mission/tuto...
Below is a given ArrayList class and Main class Your Dreams Our Mission/tuto...
 
Data type list_methods_in_python
Data type list_methods_in_pythonData type list_methods_in_python
Data type list_methods_in_python
 
Python list
Python listPython list
Python list
 
Python :variable types
Python :variable typesPython :variable types
Python :variable types
 
Java Week4(C) Notepad
Java Week4(C)   NotepadJava Week4(C)   Notepad
Java Week4(C) Notepad
 
An Introduction to Tuple List Dictionary in Python
An Introduction to Tuple List Dictionary in PythonAn Introduction to Tuple List Dictionary in Python
An Introduction to Tuple List Dictionary in Python
 
An Introduction To Python - Lists, Part 2
An Introduction To Python - Lists, Part 2An Introduction To Python - Lists, Part 2
An Introduction To Python - Lists, Part 2
 
File handling in c language
File handling in c languageFile handling in c language
File handling in c language
 
1. python
1. python1. python
1. python
 
Billing Software By Harsh Mathur.
Billing Software By Harsh Mathur.Billing Software By Harsh Mathur.
Billing Software By Harsh Mathur.
 
Python Lecture 11
Python Lecture 11Python Lecture 11
Python Lecture 11
 
Pytho_tuples
Pytho_tuplesPytho_tuples
Pytho_tuples
 
C language header files
C language header filesC language header files
C language header files
 
Groovy
GroovyGroovy
Groovy
 

Viewers also liked

Games C L
Games  C LGames  C L
Games C L
gail.dyer
 
Basic version of MS Paint created using Turbo C++
Basic version of MS Paint created using Turbo C++Basic version of MS Paint created using Turbo C++
Basic version of MS Paint created using Turbo C++
Jaison Sabu
 
Mouse and Cat Game In C++
Mouse and Cat Game In C++Mouse and Cat Game In C++
Mouse and Cat Game In C++
Programming Homework Help
 
1 c – graphic designs
1 c – graphic designs1 c – graphic designs
1 c – graphic designs
Haseeb Patel
 
C ppt
C pptC ppt
C ppt
jasmeen kr
 
INTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMINGINTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMING
Abhishek Dwivedi
 

Viewers also liked (6)

Games C L
Games  C LGames  C L
Games C L
 
Basic version of MS Paint created using Turbo C++
Basic version of MS Paint created using Turbo C++Basic version of MS Paint created using Turbo C++
Basic version of MS Paint created using Turbo C++
 
Mouse and Cat Game In C++
Mouse and Cat Game In C++Mouse and Cat Game In C++
Mouse and Cat Game In C++
 
1 c – graphic designs
1 c – graphic designs1 c – graphic designs
1 c – graphic designs
 
C ppt
C pptC ppt
C ppt
 
INTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMINGINTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMING
 

Similar to Word games in c

Dictionary
DictionaryDictionary
Dictionary
Pooja B S
 
Python Data Types with realistical approach.pptx
Python Data Types with realistical approach.pptxPython Data Types with realistical approach.pptx
Python Data Types with realistical approach.pptx
MuhammadUmar890FETBS
 
Python Lecture 8
Python Lecture 8Python Lecture 8
Python Lecture 8
Inzamam Baig
 
Beginner's Python Cheat Sheet.pdf
Beginner's Python Cheat Sheet.pdfBeginner's Python Cheat Sheet.pdf
Beginner's Python Cheat Sheet.pdf
AkhileshKumar436707
 
beginners_python_cheat_sheet_pcc_all (1).pdf
beginners_python_cheat_sheet_pcc_all (1).pdfbeginners_python_cheat_sheet_pcc_all (1).pdf
beginners_python_cheat_sheet_pcc_all (1).pdf
ElNew2
 
Beginner's Python Cheat Sheet
Beginner's Python Cheat SheetBeginner's Python Cheat Sheet
Beginner's Python Cheat Sheet
Verxus
 
2. Python Cheat Sheet.pdf
2. Python Cheat Sheet.pdf2. Python Cheat Sheet.pdf
2. Python Cheat Sheet.pdf
MeghanaDBengalur
 
python cheat sheat, Data science, Machine learning
python cheat sheat, Data science, Machine learningpython cheat sheat, Data science, Machine learning
python cheat sheat, Data science, Machine learning
TURAGAVIJAYAAKASH
 
Files
FilesFiles
Python cheatsheet for beginners
Python cheatsheet for beginnersPython cheatsheet for beginners
Python cheatsheet for beginners
Lahore Garrison University
 
Beginners python cheat sheet - Basic knowledge
Beginners python cheat sheet - Basic knowledge Beginners python cheat sheet - Basic knowledge
Beginners python cheat sheet - Basic knowledge
O T
 
Python revision tour II
Python revision tour IIPython revision tour II
Python revision tour II
Mr. Vikram Singh Slathia
 
Data Structure In C#
Data Structure In C#Data Structure In C#
Data Structure In C#
Shahzad
 
Python Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayPython Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard Way
Utkarsh Sengar
 
Python programming : Strings
Python programming : StringsPython programming : Strings
Python programming : Strings
Emertxe Information Technologies Pvt Ltd
 
Chap 2 Arrays and Structures.ppt
Chap 2  Arrays and Structures.pptChap 2  Arrays and Structures.ppt
Chap 2 Arrays and Structures.ppt
shashankbhadouria4
 
Chap 2 Arrays and Structures.pptx
Chap 2  Arrays and Structures.pptxChap 2  Arrays and Structures.pptx
Chap 2 Arrays and Structures.pptx
shashankbhadouria4
 
beginners_python_cheat_sheet_pcc_all (3).pptx
beginners_python_cheat_sheet_pcc_all (3).pptxbeginners_python_cheat_sheet_pcc_all (3).pptx
beginners_python_cheat_sheet_pcc_all (3).pptx
HongAnhNguyn285885
 
File handling in pythan.pptx
File handling in pythan.pptxFile handling in pythan.pptx
File handling in pythan.pptx
NawalKishore38
 
Linq introduction
Linq introductionLinq introduction
Linq introduction
Mohammad Alyan
 

Similar to Word games in c (20)

Dictionary
DictionaryDictionary
Dictionary
 
Python Data Types with realistical approach.pptx
Python Data Types with realistical approach.pptxPython Data Types with realistical approach.pptx
Python Data Types with realistical approach.pptx
 
Python Lecture 8
Python Lecture 8Python Lecture 8
Python Lecture 8
 
Beginner's Python Cheat Sheet.pdf
Beginner's Python Cheat Sheet.pdfBeginner's Python Cheat Sheet.pdf
Beginner's Python Cheat Sheet.pdf
 
beginners_python_cheat_sheet_pcc_all (1).pdf
beginners_python_cheat_sheet_pcc_all (1).pdfbeginners_python_cheat_sheet_pcc_all (1).pdf
beginners_python_cheat_sheet_pcc_all (1).pdf
 
Beginner's Python Cheat Sheet
Beginner's Python Cheat SheetBeginner's Python Cheat Sheet
Beginner's Python Cheat Sheet
 
2. Python Cheat Sheet.pdf
2. Python Cheat Sheet.pdf2. Python Cheat Sheet.pdf
2. Python Cheat Sheet.pdf
 
python cheat sheat, Data science, Machine learning
python cheat sheat, Data science, Machine learningpython cheat sheat, Data science, Machine learning
python cheat sheat, Data science, Machine learning
 
Files
FilesFiles
Files
 
Python cheatsheet for beginners
Python cheatsheet for beginnersPython cheatsheet for beginners
Python cheatsheet for beginners
 
Beginners python cheat sheet - Basic knowledge
Beginners python cheat sheet - Basic knowledge Beginners python cheat sheet - Basic knowledge
Beginners python cheat sheet - Basic knowledge
 
Python revision tour II
Python revision tour IIPython revision tour II
Python revision tour II
 
Data Structure In C#
Data Structure In C#Data Structure In C#
Data Structure In C#
 
Python Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayPython Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard Way
 
Python programming : Strings
Python programming : StringsPython programming : Strings
Python programming : Strings
 
Chap 2 Arrays and Structures.ppt
Chap 2  Arrays and Structures.pptChap 2  Arrays and Structures.ppt
Chap 2 Arrays and Structures.ppt
 
Chap 2 Arrays and Structures.pptx
Chap 2  Arrays and Structures.pptxChap 2  Arrays and Structures.pptx
Chap 2 Arrays and Structures.pptx
 
beginners_python_cheat_sheet_pcc_all (3).pptx
beginners_python_cheat_sheet_pcc_all (3).pptxbeginners_python_cheat_sheet_pcc_all (3).pptx
beginners_python_cheat_sheet_pcc_all (3).pptx
 
File handling in pythan.pptx
File handling in pythan.pptxFile handling in pythan.pptx
File handling in pythan.pptx
 
Linq introduction
Linq introductionLinq introduction
Linq introduction
 

More from Programming Homework Help

Java Assignment Help
Java  Assignment  HelpJava  Assignment  Help
Java Assignment Help
Programming Homework Help
 
C# Assignmet Help
C# Assignmet HelpC# Assignmet Help
C# Assignmet Help
Programming Homework Help
 
C# Assignmet Help
C# Assignmet HelpC# Assignmet Help
C# Assignmet Help
Programming Homework Help
 
Family tree in java
Family tree in javaFamily tree in java
Family tree in java
Programming Homework Help
 
Binary tree in java
Binary tree in javaBinary tree in java
Binary tree in java
Programming Homework Help
 
Bank account in java
Bank account in javaBank account in java
Bank account in java
Programming Homework Help
 
Card Games in C++
Card Games in C++Card Games in C++
Card Games in C++
Programming Homework Help
 

More from Programming Homework Help (7)

Java Assignment Help
Java  Assignment  HelpJava  Assignment  Help
Java Assignment Help
 
C# Assignmet Help
C# Assignmet HelpC# Assignmet Help
C# Assignmet Help
 
C# Assignmet Help
C# Assignmet HelpC# Assignmet Help
C# Assignmet Help
 
Family tree in java
Family tree in javaFamily tree in java
Family tree in java
 
Binary tree in java
Binary tree in javaBinary tree in java
Binary tree in java
 
Bank account in java
Bank account in javaBank account in java
Bank account in java
 
Card Games in C++
Card Games in C++Card Games in C++
Card Games in C++
 

Recently uploaded

Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Denish Jangid
 
Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...
Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...
Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...
Diana Rendina
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
haiqairshad
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
TechSoup
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
Jyoti Chand
 
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
imrankhan141184
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience
Wahiba Chair Training & Consulting
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
EduSkills OECD
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
Celine George
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
GeorgeMilliken2
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 

Recently uploaded (20)

Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
 
Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...
Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...
Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
 
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 

Word games in c

  • 1.
  • 2. This is a problem where the word ho olate a e adefro the sy ols of ele e ts o the periodic table like- "C", "H", "O", "C", "O", "La", "Te" using the symbols Carbon, Hydrogen, Oxygen, Lanthanum and Tellurium. Cobalt can also be used for the "Co" before "La". The word "banana" or "bananas" can be made with "Ba", "Na", "Na" and "S", but not with "N" because there is no "A" or "An" on the periodic table. Trying to use Nitrogen "N" would appear to fail when checking the rest of the word, but using Sodium "Na" would work for the rest. So one gotto try any combination of 1 and 2 letter element symbols. In this C program, determine if a lowercase word can be made with any combination of 1 or 2 letter element symbols. The list of chemical elements will come from a text file named chemelements.txtin which the 4 lines of the file will each contain 25 atomic symbols. Input the filename from the keyboard. Let theuser enter words to check for from the keyboard. Assume correct input (spelling). Output "Yes" or "No" for each word indicating if it can be made from the element symbols. The program is as follows: #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> /* convert the word to lower case */ voidtoLower(char word[]); /* read elements names from the given file * convert their name into lower cases */ intreadElements(char filename[], char names[100][3]); /* check if the word starting from index (pos) can be formed * by using the element names in then names arrray */ int search(char names[100][3], int count, char word[], intpos); int main() { char filename[256]; char word[256]; char names[100][3]; /* element names*/ int count; /* ask the user to enter the filename */ printf("Enter the file name: "); scanf("%s", filename); /* ask the user to enter the word to search */ printf("nEnter the word: "); scanf("%s", word); toLower(word); /* read the element names from the file */ count = readElements(filename, names);
  • 3. /* search */ if (search(names, count, word, 0) == 1) { printf("Yesn"); } else { printf("Non"); } } /* convert the word to lower case */ voidtoLower(char word[]) { int i; for (i = 0; word[i] != 0; i++) { /* convert to lower case */ word[i] = tolower(word[i]); } } /* readingthe elements names from the given file and * convert their name into lower cases */ intreadElements(char filename[], char names[100][3]) { int count = 0; FILE *in = fopen(filename, "r"); if (in == NULL) { printf("Error: could not read file %s.n", filename); exit(-1); } /* read names one by one until the end of file */ while (fscanf(in, "%s", names[count]) == 1) { toLower(names[count]); count ++; } fclose(in); return count; } /* Here it is checked that if the word starting from index (pos) can *be formed by using the element names in then names arrray */ int search(char names[100][3], int count, char word[], intpos) { int i; intlen = strlen(word); if (pos == len) { /* already the end of word, thus its true */ return 1; } /* check if the part is one character in word, * if the remaining word can be generated with element names */ for (i = 0; i < count; i++) {
  • 4. int k = strlen(names[i]); if (k == 1 && word[pos] == names[i][0]) { /* found a matched single character element name, * check the rest part */ if (search(names, count, word, pos + 1)) { return 1; } } } /* In the below section it is checked that if the part is two *characters in word,if the remaining word can be generated with element names */ if (pos + 1 <len) { for (i = 0; i < count; i++) { int k = strlen(names[i]); if (k == 2 && word[pos] == names[i][0] && word[pos + 1] == names[i][1]) { /* found a matched two characters element name, then * check the rest part */ if (search(names, count, word, pos + 2)) { return 1; } } } } return 0; }