- HubPages»
- Technology»
- Computers & Software»
- Computer Science & Programming
C Program for Rewriting the Strings
C language is really very helpful for software developing purposes . Following Source code is of a program which will help you communicate with your friends easily that too in a secret manner . This program is used to re write the given string replacing each character with the next coming character in the alphabet series . For example , if I entered Amandeep , then it will display it as Bnboeffq .
Copy the given whole source code in your notepad and save it as with the extension *.c or *.cpp . Then open the file with your compiler and run it . You will enjoy the program for sure . It is also an exercise for the Computational Technique Subject .
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
char a[100],b[100];
int i,len,I;
puts("Enter you string");
gets(a);
len=strlen(a);
for(i=0;i<=len;i++)
{
I=int(a[i]);
I++;
if(I==91)
{I=65;}
else if(I>122)
{I=97;}
else if(I==33)
{I=32;}
b[i]=char(I);
}
printf("The output is : \n");
for(i=0;i<len;i++)
printf("%c",b[i]);
getch();
}
For its application of secret communication , the other person must have c program which will rewrite the entered string replacing each character with its previous character which is as follows :
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
char a[100],b[100];
int i,len,I;
puts("Enter you string");
gets(a);
len=strlen(a);
for(i=0;i<=len;i++)
{
I=int(a[i]);
I--;
if(I==96)
{I=122;}
else if(I==64)
{I=90;}
else if(I==31)
{I=32;}
b[i]=char(I);
}
printf("The output is : \n");
for(i=0;i<len;i++)
printf("%c",b[i]);
getch();
}
The screenshot is the proof of a working program .