The program must encrypt the characters in a string adding 2 to those located in even positions and 3 to those in odd positions. I declare string as a pointer because I do not know the length of the string that the user will enter. The program compiles, but stumbles.
#include <stdio.h>
#include <string.h>
#include <conio.h>
/*PROGRAM EXERC107*/
int main() {
char * string;
int encryp, i;
string = 0;
printf("Enter a string for encrypting:");
scanf("%s",string);
printf("\n");
for (i=0; i < strlen(string);i++)
{
if ((i % 2)==0)
{
encryp=string[i];
string[i]=encryp + 2;
}
else
{
encryp=string[i];
string[i]=encryp + 3;
}
printf("%c",string[i]);
}
getch();
return 0;
}