// 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 !

Its working fine at my end. After entering the first sentence, it asks me whether I want to continue or not. Can you give a little more detail about your problem?


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 !

First of all, why aren't you calling those functions from 'main'. Try not to be cool and declare prototypes for each function you use before doing anything else. Because whatever you're doing there is not considered a very good programming habit.

int start(void);
int input(void);
int check(void);

If you want the function to return nothing then, declare it like this:

void start(void);

Even if you want to declare those functions like you did in the above code, you should put return statement at the end of the each one like you usually do with the 'main'.

return 0;

And now for the problem you're facing.
put a "getchar()" after the scanf in the line 96 in your above code and you'll be fine. After the scanf has read your input ,a '\n' is still left in the input buffer. So whenever that scanf(in line 38) tries to take input, it will always get the '\n' left in the input buffer.

Its working fine at my end. After entering the first sentence, it asks me whether I want to continue or not. Can you give a little more detail about your problem?

yea it will.. but then insert 1 and see... it will run the start function and then not accepting any string of values, and outputting what has been input the first time..

There's a newline left in the stream the second time you call start(). Do some research on this, it's a classic and very common problem.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.