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 8736605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:20:32+00:00 2026-06-13T10:20:32+00:00

I am writing a program, that is encrypting a number, entered by user. Encryption

  • 0

I am writing a program, that is encrypting a number, entered by user. Encryption steps are performed by functions, which I have to write. The problem is that I have to use value obtained in one function, in the next function. Here is what I am trying to do:
first function reads an integer. second adds 4 to every digit of that integer. and the problem is that how to use the integer that is entered in the first function, in the second function.

 void input(int *num)
{
  int numin;
  printf("Please enter an integer greater than 99999: ");
  scanf("%d", &numin);
  while (numin<99999)
    {
      printf("Incorrect input.\n");
      printf("Please enter an integer greater than 99999: ");
      scanf("%d", &numin);
    }    
  num=&numin;
  printf("The number entered is %d\n", numin);
  return;
}
int add4(int num)
{
  int a,b=1,numplus4;
  int i=-1;
  for (numplus4=0; b==0;)
    {
      a=num%10;
      b=num/10;
      num=b;
      a+=4;
      if (a>9)
    a-=10;
      i++;
      numplus4+=a*pow(10, i);
    }
  num=numplus4;
  printf("%d\n", num);
  return num;
}

I have googled on this topic: but all i got didnot help me, most of answers are for Javascripts, but I am using C.

  • 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-13T10:20:33+00:00Added an answer on June 13, 2026 at 10:20 am

    You are not actually returning anything from the input function.

    Instead of passing a pointer to the number being set (which you do not set correctly) you should use the return statement to return the value:

    int input(void)
    {
        ...
    
        return numin;
    }
    

    Then you can use it as this:

    int main(void)
    {
        int result = add4(input());
        printf("Result is %d\n", result);
    
        return 0;
    }
    

    The reason you don’t return anything in your current function, is because in the input function the parameter num is local to that function. So any changes you made to it (like assigning to it) is lost when the function return.

    What you are doing is potentially dangerous as it borders on undefined behaviour. You want to make the pointer point to a local variable, but when the function returns the memory where that local variable is stored is no longer valid to access.

    You can use pointer arguments to return values though, this is what is called passing arguments by reference. But you don’t assign pointer like you do, instead you use the dereferencing operator (unary *):

    *num = numin;
    

    For it to be valid though, you have to pass the address of an already allocated variable, like this:

    int num;
    input(&num);  /* Use the address-of operator to create a pointer */
    

    However, I suggest using the solution in the first part of this answer, until you know more about pointers and how they work.

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

Sidebar

Related Questions

Im writing a program that should read input via stdin, so I have the
I'm writing a program that lets the user input 6 temperature readings, and then
I am writing a program that manages a bunch of timers. The user has
I'm writing a program that lets the user draw a hollow rectangle on the
I'm writing a program that is using the functions sin() and cos() from the
I'm writing a program that relies on the user having third party packages already
I am currently writing a program which takes user input and creates rows of
I'm writing a program that gathers user input for two file names, and opens
I have tried writing program that plays a sound file but have been unsuccessful
I'm writing a program that creates an object which holds to inputs from the

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.