The elementary C program we were working with is now updated with a little bit of command line checking.
#include<stdio.h>
int addnumbers(int num_1, int num_2)
{
int sum = 0;
sum = num_1 + num_2;
return sum;
}
int subnumbers(int num_1, int num_2)
{
int subtrt =0;
subtrt = num_1 - num_2;
return subtrt;
}
int main(int argc, char **argv)
{
if (argc < 2)
{
printf("Correct usage: tst2 <1st number> <2nd number>\n");
return 0;
}
else
{
int num_1 = atoi(argv[1]);
int num_2 = atoi(argv[2]);
printf("\n\n Welcome to simple add and subtract program\n\n\n");
printf("Sum of %d + %d = %d\n\n", num_1, num_2, addnumbers(num_1, num_2));
printf("Difference of %d - %d = %d\n\n",num_1, num_2,subnumbers(num_1, num_2));
getchar();
return 0;
}
}
IT Security practitioner with a deep interest in Cyber Security, Compliance, Cloud Security, Penetration testing, Big Data Analytics, Cloud Automation (Puppet), Computer Forensics toolkits, Converged and Hyper-Converged infrastructure. In my free time, I like riding my motorcycle on curvy roads while keeping an eye out for wildlife which might cut my ride short
Monday, March 3, 2014
Updated program with command line checking included.
Life long learner. All thoughts and ideas defined in this blog are my own and not associated in any manner with my clients, employees or employers.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment