Thread: Caeser Cipher help

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    6

    Caeser Cipher help

    hi, i could use a little help today. I'm trying to make a program that will take a string input and according to a key edit each letter by moving it over in the alphabet with a wrap-around and output it. So right now the compiler errors i'm getting right now are
    42:2 error:invalid operands to binary * (have 'int' and 'char *')
    44:2 expected ';' before 'if'
    51:1 expected declaration or statement at end of input

    so i've been having trouble cause i'm just trying to use the function to edit the array with pointers and the array is characters so i don't know what i'm doing wrong. Any help would be greatly appreciated, thanks!

    Code:
    /* Caesar Cipher Project
       Input a message and a shift amount
       then prints out the encrypted message
    
       Programmer:Derek Roncal
       Date:10/12/11
    */
    #include<stdio.h>
    #include<string.h>
    
    void letter_switcher(char a[], int b);
    
    int main(void)
    {
      int k;
      char input_buffer[81];
      printf("Enter message to be encrypted:");
      fgets(input_buffer, 80, stdin);
      printf("Enter shift amount (1-15):");
      scanf("%d", &k);
      letter_switcher(input_buffer,k);
     
    
    
    
    
     printf("%s",input_buffer);    
      return 0;
    }
    
    
    
    void letter_switcher(c a[],int b)
    { int i;
      char*p;
      p=a;
      char code; 
      for(p=0; *p !='\0'; p++)
        { if((*p >= 'A' && *p <= 'Z') || (*p >= 'a' && *p <= 'z'))
          {
        code=*p
        *p=((code-'A')+ b) % 26 + 'A'
        
        if((*p >= 'a' && *p <= 'a')
        { 
          code=*p;
          *p=((code-'A')+ b) % 26 + 'A';
            }
         }
    
      
    }

  2. #2
    Registered User TheBigH's Avatar
    Join Date
    May 2010
    Location
    Melbourne, Australia
    Posts
    426
    You've got a missing semicolon at the end of line 41.
    Code:
    while(!asleep) {
       sheep++;
    }

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
        if((*p >= 'a' && *p <= 'a')
    Count the pairs of parenthesis.
    Code:
      code=*p
        *p=((code-'A')+ b) % 26 + 'A'
    Statements end in a ; and you don't seem to have any.


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Cracking a Cipher
    By eeengenious in forum C Programming
    Replies: 1
    Last Post: 03-29-2011, 02:14 AM
  2. cipher
    By mrsirpoopsalot in forum C++ Programming
    Replies: 4
    Last Post: 02-15-2009, 09:24 PM
  3. Caeser Cipher
    By L_U_K_E in forum C++ Programming
    Replies: 35
    Last Post: 06-30-2006, 07:15 AM
  4. my first cipher
    By Nor in forum C++ Programming
    Replies: 8
    Last Post: 07-09-2003, 01:09 PM