I have been viewing two videos of the GNU debugger expert series and found them easy to follow and practice. Even writing the source code by hand for the second video was fun as I have not touched C in a long time now. It has been so long that I forgot that the program need two command line arguments and got a segmentation fault when I ran the program without command line arguments.
Given below is the program.
#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)
{
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;
}
This elementary program does not have error checking which is why is crashes when run without command line arguments.
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
Saturday, March 1, 2014
Security Tube GNU Debugger Expert Video Series
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