#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main(int argc,char *argv[])
{
int sum=0,i;
//if wrong number of command line arguments
if(argc<3)
{
printf("Incorrect number of arguments:\n");
getch();
return 0;
}
//Add all the numbers entered using atoi function
for(i=1;i<argc;i++)
{
sum+=atoi(argv[i]); //string to number
}
//print the sum
printf("Ans=%d",sum);
getch();
}
This blog will cover all important aspects of 'C' 'C++', 'Data Structures in C' and other Technical stuffs. In this blog you will find good C Interview Questions Answers. I will be posting both multiple choice and subjective type C interview questions and answers. Tutorials will be posted from time to time that will focus on problem solving.
Saturday, April 14, 2012
C Program to show use of command line arguments
Labels:
c,
c language,
programming,
simple c programs
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment