Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8771955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:55:12+00:00 2026-06-13T17:55:12+00:00

Possible Duplicate: Sizeof an array in the C programming language? I’ve been fiddling with

  • 0

Possible Duplicate:
Sizeof an array in the C programming language?

I’ve been fiddling with C to become better acquainted with it and think I may have stumbled upon a initialization/pointer issue that I’m unsure of how to resolve. The below program is an implementation of ROT13, so it takes an input string, and shifts each letter by 13, resulting in the cipher text. The output of my program displays the correct shift, but it won’t work for more than 4 characters, making me wonder if sizeof is being used incorrectly. Any other suggestions are appreciated, I’m sure I’ve messed a few things up at this point.

#include <stdio.h>
#include <string.h>

void encrypt(char *);

int main(void){

    char input[] = "fascs";
    encrypt(input);

    return 0;
}

void encrypt(char *input){

    char alphabet[] = "abcdefghijklmnopqrstuvwxyz";

    printf("Input: %s \n", input);

    int inputCount = sizeof(input);

    printf("Characters in Input: %i \n\n", inputCount);

    //holds encrypted text
    char encryptedOutput[inputCount];

    //Initialize counters
    int i, j = 0;

    // loop through alphabet array, if input=current letter, shift 13 mod(26),
    // push result to output array, encryptedOutput
    for(i = 0; i < inputCount; i++){
        for(j = 0; j < 26; j++){
            if(input[i] == alphabet[j]){
                encryptedOutput[i] = alphabet[(j + 13) % 26];
            }
        }
    }

    //Nul Termination for printing purposes
    encryptedOutput[i] = '\0';

    printf("Rot 13: %s \n\n", encryptedOutput);

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T17:55:13+00:00Added an answer on June 13, 2026 at 5:55 pm

    sizeof() in encrypt will not behave as you want it to. Inside encrypt, the sizeof(char *) is 4(on a 32bit machine) or 8(on a 64 bit machine), which you can see is the size of a pointer.

    To get the sizeof(input) you must change sizeof to strlen. Hence solution = strlen(input)

    Why this happens?? when you pass an array into a function, that array is internally represented as a pointer. At the called-function’s end input is just a pointer, which gives either 4 or 8 bytesize depending upon your machine.

    To get the sizeof of input, just use a macro like this:
    #define SIZEOF(x) (sizeof(x)/sizeof(x[0]))
    and use this in the function that defines x. In your program, x is input in main()

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Sizeof an array in the C programming language? I have been working
Possible Duplicate: Sizeof an array in the C programming language? I have an array
Possible Duplicate: Sizeof an array in the C programming language? I'm trying to write
Possible Duplicate: Sizeof an array in the C programming language? Why does a C-Array
Possible Duplicate: Sizeof an array in the C programming language? Why is the size
Possible Duplicate: Sizeof an array in the C programming language? #include stdafx.h #include <string>
Possible Duplicate: sizeof array clarification I have 2 arrays declared GLfloat gCubeVertexData[216] = {
Possible Duplicate: How to find the sizeof(a pointer pointing to an array) I have
Possible Duplicate: How to find the sizeof(a pointer pointing to an array) Sizeof array
Possible Duplicate: Sizeof array passed as parameter Given the function below I understand that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.