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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:54:11+00:00 2026-06-15T06:54:11+00:00

The following line has the problem int (*f)(int, int) = (argv[2][0] == ‘d’) ,

  • 0

The following line has the problem int (*f)(int, int) = (argv[2][0] == 'd') , on compiling it says declaration not allowed here . Should the line be declared at the start , any better way of doing this .Any suggestions would be greatly appreciated?

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

int encode(int ch, int key) { 
        if (islower(ch)) {
                ch = (ch-'a' + key) % 26 + 'a';
                ch += (ch < 'a') ? 26 : 0;
        }
        else if (isupper(ch)) {
                ch = (ch-'A' + key) % 26 + 'A';
                ch += (ch < 'A') ? 26 : 0;
        }
        return ch;
}

int decode(int ch, int key) { 
        return encode(ch, -key);
}

int main(int argc, char **argv) { 
        int ch;
        int key;

        if (argc < 2) {
                printf("USAGE: cipher <integer key> <encode | decode>\n");
                printf("Then, just type your text and it will automatically output the en/de crypted text! :)\n");
                return 1;
        }

        key = atoi(argv[1]);
        if (key < 1 || key > 25) {
                printf("Key is invalid, or out of range. Valid keys are integers 1 through 25.\n");
                return 1;
        }

        int (*f)(int, int) = (argv[2][0] == 'd') ? 
                decode : 
                encode;

        while (EOF != (ch=getchar()))
                putchar(f(ch, key));

        return 0;
}
  • 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-15T06:54:12+00:00Added an answer on June 15, 2026 at 6:54 am

    In C (prior to C99), you have to declare variables at the start of a block.

    Either compile your code as C99, or change the code so that f is declared at the start of a block.

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

Sidebar

Related Questions

Alex's answer has the following line when translated to English print %2d. %8.2f %8.2f
My routes.php has the following line of code: Router::connect('/', array('controller' => 'users', 'action' =>
I have a #!/bin/sh script that has the following line: if [ ! -x
The following line in my C program should provided All/Group/Owner read and write permissions
Hi following code sample seems to have some problem or either it has to
I have the following format. Each line has two integers and the file is
The following code shows error as StandardOut has not been redirected or the process
The following line: string cellData = d.XPathSelectElement(cellSelector).Value; Throws an exception stating The XPath expression
The following line of code causes a JScript object expected error in IE: hideElements.apply(window,
The following line of code <% invite.accepted ? { @going, @not_going = 'selected', ''

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.