command line program, something wrong in the argv
OS win98SE
compiler dev c++
problem : please check at my modulus sign at check int() function, and also if can, please let me know what happen while i'm passing array, if you're generouse enough, please re write this code using pointer instead of array, thank you
/*
Program name : chkinp.exe
Programmer :
Description : A program which checking number of arguments that are passed
from the command-line. The program itself will determine
what kind of argument that has been passed by the user, whether
a number, a palindrome, a word
Date : 09/26/2001
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define puts printf
int check_int(char argv[]);
int check_float(char argv[]);
int check_alpha(char argv[]);
int main(int argc, char **argv)
{
int i,c_word, c_palind, c_numb; /*declaring integer type for counter*/
for(i=1;i<argc;i++)
{
argv[i];
if(isdigit(argv[i])&&ispunct(argv[i]))
c_numb+=check_float(argv[i]);
else if(isdigit(argv[i]))
c_numb+=check_int(argv[i]);
}
for(i=1;i<argc;i++)
{
argv[i];
if(isalpha(argv[i]))
c_word+=check_alpha(argv[i]);
}
puts(" There were %d argument(s) \n ", argc-1 ); /* total number of arguments */
puts(" %d word(s) \n ", c_word ); /* total number of words */
//puts(" %d palindrom(s)\n ", c_palin); /* total number of palindromes */
puts(" %d number(s) \n ", c_numb ); /* total number of numbers */
return 0;
}
int check_float(char argv[])
{
float a = 0.0;
a = atof(argv);
printf("%f",a);
if((a%2.0)==0.0)
puts("The number %f is a real number that is even\n",a);
else
puts("The number %f is a real number that is odd\n",a);
return 1;
}
int check_int(char argv[])
{
int b = 0;
b = atoi(argv);
if((b%2)==0)
puts("The number %d is a integer number that is even\n",a);
else
puts("The number %d is a integer number that is odd\n",a);
return 1;
}
int check_alpha(char argv[])
{
puts("%s\n", argv);
return 1;
}