About Me

My photo
Raipur, Chhattisgarh, India
Hi , I am Amit Thakur. I have worked as a QA Engineer for two years and as a Java Developer for one year in NIHILENT TECHNOLOGIES PVT. LTD., Pune.Currently I am working as DEAN (Research & Development) in Bhilai Institute of Technology, Raipur.

Tuesday, September 3, 2013

C Program to Encode a String and Display Encoded String

Problem Statement :

Read a five-letter word into the computer, then encode the word on a letter-by-letter basis by subtracting 30 from the numerical value that is used to represent each letter. Thus if the ASCII character set is being used, the letter a (which is represented by the value 97) would become a C (represented by the value 67), etc. Write out the encoded version of the word. Test the program with the following words: white, roses, Japan, zebra.

Program : To Encode Entered String and Display Encoded String

#include<stdio.h>
#include<conio.h>

char* encode(char* str)
{
 int i=0;

 while(str[i]!='')      // Loop Continues till NULL
   {
   str[i] = str[i] - 30;  // Subtract 30 From Charcter
   i++;
   }

 return(str);             //  Returning String
}
//----------------------------------------
void main()
{
 char *str;
 clrscr();

 printf("nEnter the String to be Encode : ");
 gets(str);

 str = encode(str);

 printf("nEncoded String : %s",str);

 getch();
}
Output :
Enter the String to be Encode : white

Encoded String : YJKVG

Enter the String to be Encode : roses

Encoded String : TQUGU

Enter the String to be Encode : Japan

Encoded String : ,CRCP

Enter the String to be Encode : zebra

Encoded String : GDTC

No comments: