The goal of my assignment is to create a program that takes a string of words and encodes or decodes the string using a simple substitution cypher.
I've gotten a decent amount done but I am stuck at the part where I actually have to encrypt and decrypt using the offset that the user has input.
This is what I have, can anybody lend a hand?

include <stdio.h>

int main () {
#include <stdio.h>

int main () {

   char alpha[26] = "abcdefghijklmnop";
   char*encrypt(char*str,int offset);
   char*decrypt(char*str,int offset);

   int option;
   int offset;
   char str;

  char toencode(int alpha, int ALPHA);
  char todecode(int alpha, int ALPHA);

   printf("Select an option.\n");
   printf("1. Encrypt File\n");
   printf("2. Decrypt File\n");

   if(option == 1)
   else if(option == 2)
   printf("invalid entry\n");
   return 0;

   printf("Please enter a number for the offset.");

   printf("Type entry to encrypt.\n");
   scanf("%s", &str);

return 0;

Line 43: you ask the user for a string but the variable str is only a single character not a string (an array of char)

Your 2 arrays alpha and ALPHA seem unlikely, at this stage to be of any use.

Your encrypt function just needs to read everry letter in the string and replace it with another letter offset places down the alphabet. You could do this as modulo arithmetic, convert the letter to an index into the alphabet, add the offset in modulo 26 arithmatic.

This article has been dead for over six months. Start a new discussion instead.