Basic

Switch Case

Goto

Operators

if Statement

Nested if

While Loop

For Loop

Array

Patterns

Excersises


How to Create FLAMES Game Using C Program


FLAMES game is know the relationship with their partner.This example shows how to create FLAMES game using JavaScript.

FLAMES stands for

  • F-Friend
  • L-Love
  • A-Affection
  • M-Marriage
  • E-Enemy
  • S-Sibling
Example : pgm.c
#include<stdio.h>
#include<string.h>
int main(){
    int i,j,n1,n2,len=0,x=0,y=0;
    char name1[100],name2[100],cpy_name1[100],cpy_name2[100],result[10],f[10];
    strcpy(f,"FLAMES");

    printf("\nEnter First Name : ");
    gets(name1);
    printf("\nEnter Second Name : ");
    gets(name2);

    //Remove space from name
    remove_space(name1);
    remove_space(name2);

    //Copy name to temp variable
    strcpy(cpy_name1,name1);
    strcpy(cpy_name2,name2);
    strcpy(cpy_name1,strlwr(cpy_name1));
    strcpy(cpy_name2,strlwr(cpy_name2));

    //Find length of name
    n1=strlen(cpy_name1);
    n2=strlen(cpy_name2);

    //Set '*' character to matched letter of cpy_name1 and cpy_name2
    for(i=0;i<n1;i++){
        for(j=0;j<n2;j++){
            if(cpy_name1[i]==cpy_name2[j] && cpy_name1[i]!='*'){
                cpy_name1[i]='*';
                cpy_name2[j]='*';
            }
        }
    }

    //Count remaining letters from cpy_name1 and cpy_name2
    len=getCount(cpy_name1)+getCount(cpy_name2);

    //Remove the letters as by count from FLAMES one by one and find last letter.
    for(;getCount(f)!=1;){
        if(y>5){
           y=0;
        }
        if(f[y]!='*'){
            x++;
        }
        if(x%len==0)
        {
            f[y]='*';
        }
        y++;
    }
    getResultFromLetter(f,result);

    printf("The Relationship between '%s' and '%s' will end in '%s'.",name1,name2,result);
    return 0;
}

//Count Letters (without '*' character)
int getCount(char a[10]){
    int c=0,i;
    for(i=0;i<6;i++){
        if(a[i]!='*'){
            c++;
        }
    }
    return c;
}

//Find remaining letter from FLAMES
void getResultFromLetter(char a[10],char result[10]){
    int i;
    char c='-';
    for(i=0;i<6;i++){
        if(a[i]!='*')
        {
            c=a[i];
        }
    }
    switch(c){
        case 'F':
            strcpy(result,"Friend");
            break;
        case 'L':
            strcpy(result,"Love");
            break;
        case 'A':
            strcpy(result,"Affection");
            break;
        case 'M':
            strcpy(result,"Marriage");
            break;
        case 'E':
            strcpy(result,"Enemy");
            break;
        case 'S':
            strcpy(result,"Sister");
            break;
    }
}

//Remove space from string
void remove_space(char str[100]){
    int i,k=0;
    char a[100];
    for(i=0;str[i]!='\0';i++){
        if(str[i]!=' '){
            a[k]=str[i];
            k++;
        }
    }
    strcpy(str,a);
    str[k]='\0';
}

Output:

Enter First Name : Ram

Enter Second Name : Sara

 The Relationship between 'Ram' and 'Sara' will end in 'Friend'.