Thread: Please help! Novice coder trying to figure c out.

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    131
    In the call to your encryption procs:

    Code:
    char simpleEncrypt(char input[20])
    You're designating a return of a single char data type, but you're returning only the first character of your parameter:

    Code:
     return *input;
    You could simply pass the array from main, receive it as a pointer, get the length (for bounds checking) and do your manipulation on that with no return value. If you pass an unsubscripted array, you pass the address of it allowing you to change the contents, so when the function returns, the changes stay.

    Segmentation faults can indicate accessing an array out of bounds or attempting to write to a NULL pointer or a pointer that has not been allocated/initialized.
    Last edited by Cynic; 04-29-2012 at 05:12 PM.

  2. #2
    Registered User
    Join Date
    Apr 2012
    Posts
    10
    So you're saying to have something like:
    Code:
    void simpleEncrypt(char input[])
    {
      int i, len = strlen(input);
      //for loop goes through all the characters in input and adds 1 to the ascii value 
      //of each character
      for(i = 0;i < len; i++)
        {
          input[i]++;
          //if the character is now ascii value 91 then we must loop around to ascii 
          //value 65. In other words goes from Z to A.
          if(input[i] == 91)
        {
          input[i] = 65;
        }
          //if the character is now ascii value 123 then we must loop around to ascii
          //value 97. In other words goes from z to a.
          else if(input[i] == 123)
        {
          input[i] = 97;
        }
        }
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C# for a C++ coder
    By KIBO in forum C# Programming
    Replies: 5
    Last Post: 04-07-2012, 01:10 AM
  2. new coder using Dev C++
    By newcoder3333 in forum C++ Programming
    Replies: 3
    Last Post: 07-29-2006, 05:35 PM
  3. HL2 mod needs coder
    By livewire in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 07-30-2005, 10:29 AM
  4. Replies: 10
    Last Post: 06-17-2005, 10:00 PM
  5. Profile of a coder
    By iain in forum A Brief History of Cprogramming.com
    Replies: 21
    Last Post: 08-20-2001, 06:05 AM

Tags for this Thread