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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:35:10+00:00 2026-06-11T13:35:10+00:00

This program is first forked then run by execlp, it’s calling program passes in

  • 0

This program is first forked then run by execlp, it’s calling program passes in two numbers, a power and a base.

int main(int argc, char *argv[])
{
    int pid = getpid();
    printf("Calculator Process[%d]: started\n",pid);
    double base, power;
    sscanf(argv[1],"%d",&base);
    sscanf(argv[2],"%d",&power);
    double number = pow(base,power);
    printf("Calculator Process[%d]: %d ^^ %d == %d\n",pid,base,power,number);
    printf("Calculator Process[%d]: exiting\n",pid);
    return 1;
}

Lets say I pass into it base 3, power 5. This is what I get:

base = 4263 -- this also happens to be the PID. 
power = -1 
raised to power: 714477568

Calling line:

execlp("./calculator","./calculator",argv[1],argv[2],(char*)0);

When I print the argvs, I get their value (as a char*, but casting fails).

Any ideas why I can’t get the values to be correctly read in?

  • 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-11T13:35:11+00:00Added an answer on June 11, 2026 at 1:35 pm

    Either read double:

    double base, power;
    sscanf(argv[1],"%lf",&base);
    sscanf(argv[2],"%lf",&power);
    

    Or scan into integers:

    int base, power;
    sscanf(argv[1],"%d",&base);
    sscanf(argv[2],"%d",&power);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This program takes the first number in a file and indicates how many numbers
this program hangs after taking first argument:- #include <stdio.h> #include <conio.h> void ellip(char*,...); int
I have a C/ncurses program that I'm debugging/maintaining. This program does ripoffline twice: first,
Ok, first off, I didn't program this page with frames! I'll be getting rid
First look at this code: class Program { static void Main(string[] args) { var
I am complete newbie for programming and this is my first real program I
Code first: '''this is main structure of my program''' from twisted.web import http from
use this website a lot but first time posting. My program creates a number
I downloaded a program implemented in Java (in this case, http://julian.togelius.com/mariocompetition2009/index.php ). I first
This program builds a dictionary out of a list based on what two index

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.