// Including the libraries to be used
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// Defining the End of line
#define EOL '\n'
//Declaring Global variables (for the sentence and the output sentence- final)
char sentence[100];
char final[100];
int i,j,ans;
int start() // Defining the start function
{
printf ("\n");
printf ("\t* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");
printf ("\t* *\n");
printf ("\t* ~~~ WELCOME TO THE ECRYPTION WORLD ~~~ *\n");
printf ("\t* *\n");
printf ("\t* *\n");
printf ("\t* *\n");
printf ("\t* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");
input(); // Calling the input function
}
int input() // Defining the start function
{
printf("\n\n Enter the word or the sentence: ");
// for (j = 0; (sentence[j] = getchar()) != EOL; ++j) ; // Using the getchar method
scanf("%[^\n]",&sentence); // Using the scanf method
//gets(sentence); // Using the gets method
for (i=0; i<strlen(sentence); i++)
{
if ((sentence[i]>= 65 && sentence[i]< 90 ) || (sentence[i]>= 97 && sentence[i]< 122 ) || (sentence[i]>= 48 && sentence[i]< 57 ))
// only lowercase and uppercase letters are changed! (A-65, Z-90 & a-97, z-122 & 0-48, 9-57)
{
final[i] = sentence[i]+1; // Incrementing the ASCII number of each character by 1
}
else if (sentence[i]== 90)
{
final[i] = 65; // Changing the value of Z to A ( ASCII number for Z is 90 & ASCII number for A is 65)
}
else if (sentence[i]== 122)
{
final[i] = 97; // Changing the value of z to a ( ASCII number for z is 122 & ASCII number for a is 97)
}
else if (sentence[i]== 57)
{
final[i] = 48; // Changing the value of 9 to 0 ( ASCII number for 9 is 57 & ASCII number for 0 is 48)
}
else
{
final[i] = sentence[i]; // For white space and other special characters, they are left unchanged
}
}
//printf("\n Your encrypted sentence is: %s\n\n ",final); // Printing the content of the array final
check(); // Calling the input function
}
int check()
{
system("cls");
printf("\n Your input sentence is: %s\n\n ",sentence);
printf("\n Your encrypted sentence is: %s\n\n ",final);
printf ("\t* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");
printf ("\t* *\n");
printf ("\t* Do you want to try again ? *\n");
printf ("\t* *\n");
printf ("\t* 1. Yes *\n");
printf ("\t* 2. No *\n");
printf ("\t* *\n");
printf ("\t* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");
printf("\n Enter your choice: ");
scanf("%i",&ans);
switch(ans)
{
case 1:
system("cls");
start(); // Calling the play function
case 2:
exit(0); // Calling the quit function
break;
default:
printf (" Enter a valid number (1 to 2)!\n");
check(); // Calling the input function
}
}
int main(int argc, char *argv[]) // The main function
{
start(); // Calling the start function
system("PAUSE");
return 0;
}
Hey guys, there is an error in this code in fact after encrypting the sentence, i wanted the program to ask if "You want to try again", but i don't know its running the program again without asking the user to input the sentence first and its outputting the array of data !
Help please !