/* I'm new on c ++ and i been strugling with this problem.
create the special functions used by this routine and
write the functions so it can be used by the main routine as shown*?

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

void swapArgs(int *parmA,int *parmB)
{
int temp = *parmA;
*parmA = *parmB;
*parmB = temp;
}

/* MAIN */
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]);

/* Swap the values. Value in parmA is moved to parmB and vice versa */
/* Reset the original values after we print the result */
printf("A=%d, B=%d. ",parmA,parmB);
swapArgs(&parmA,&parmB);
printf("Swapped values A=%d, B=%d.\n",parmA,parmB);
parmA = atoi(argv[1]);
parmB = atoi(argv[2]);

printf("\n");

system("pause");
exit(0);
}

int *temp = *parmA;
*parmA = *parmB;
*parmB = temp;

Forget pointer with temp.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.