### Pointers and Functions HELP!!!

I have this assignment:
Your task is to create the special functions used by this routine, which are shown in blue in the above program. The special functions are swapArgs, divideArgs and powerArgs You need to write the functions so that they can be used by the main routine as shown. In other words, do not change the way the functions are used, rather write your functions to accept the parameters and return the values needed to make the program work properly. Be careful to notice where pointers and variable addresses are used - the idea of this Lab is to practice writing code that uses pointers.

When it runs, it just prints ?Invalid number of arguments. Press any key to continue... then quits. How do I get the actual program to run?? PLEASE HELP!!

This is what I have:

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

void swapArgs(int *a,int *b);
int divideArgs(int *a, int *b);
double *powerArgs(double *a, double *b);

//MAIN//

double power = 0;

int main(int argc, char **argv)
{
if (argc != 3)
{
printf("?Invalid number of arguments\n");
system("pause");
exit(1);

}

int parmA = atoi(argv[1]);
int parmB = atoi(argv[2]);

printf("A=%d, B=%d. ",parmA,parmB);
swapArgs(&parmA,&parmB);
parmA = atoi(argv[1]);
parmB = atoi(argv[2]);

printf("Quotient of %d / %d is ",parmA,parmB);
divideArgs(&parmA, &parmB);
parmA = atoi(argv[1]);
parmB = atoi(argv[2]); /* Part C: Raise parmA to the power of parmB. Return pointer to the result */ /*
Reset the original values after we print the result */
printf("%d raised to the %d power is ",parmA,parmB);
printf("%.0lf \n", *powerArgs(&parmA, &parmB));

return 0;
}

void swapArgs(int *a, int *b)
{
int tempA = *a, tempB = *b;
*a = tempB;
*b = tempA;

printf("Your first number is now %d, and your second is now %d\n", *a, *b);

*a = tempA;
*b = tempB;
}

int divideArgs(int *a, int *b)
{
int tempA = *a, tempB = *b;
double divisor = *a / *b;

*a = (long) divisor;
*b = divisor - *a;

printf("%d, with the remainder being %f\n", *a, *b);

*a = tempA;
*b = tempB;
}

double *powerArgs(double *a, double *b)
{
double powerArgs = pow ((double) *a, (double) *b);
return &powerArgs;
}
Last edited on
The main function in a console application takes two arguments: the number of items and a char pointer to the items. Essentially it's an index count to a char* array. To run your program from the command line, you need call the function then include extra parameters after. For example:

C:\program program.exe arg1 arg2 arg3

The operating system will take the three command line arguments and pass them to your program through the main.

You can also specify command line arguments in your compiler so that when it attempts to run your program it will pass these parameters for you.
I went in and changed my parameters to arg1 arg2 arg3 and it still did the same thing...I am totally new to all of this and signed up for a beginners class, that wasnt for beginners. I am unsure if I am doing this correctly. Thank you!
Topic archived. No new replies allowed.