please forgive me if this is a noob question, but i'm a beginner at C, learning only for a while. I tried to write a program that sums up two numbers (provided as params to the application). The code is like this:
#include <stdlib.h> #include <stdio.h> int main( int argc, char** argv) { int a = atoi(argv[0]); int b = atoi(argv[1]); int sum = a+b; printf("%d", sum); return 0; } But I get incorrect results - huge numbers even for small inputs like 5 and 10. What is wrong here?
printf("argv[0] = %s\n", argv[0]); printf("argv[1] = %s\n", argv[1]);followed byprintf("a = %d\nb = %d\n", a, b);after the calls toatoi(). Had you done that, you probably wouldn't have needed to ask the question. (Don't forget to print a newline after the answer!).#include <cstdlib>is a C++ header. Use#include <stdlib.h>.