actually you should be using argc and not argv for your while loop.
argc = 0,1,2,3,4,5,6,7 etc ........
Code:
// this will cause you trouble so use this instead
while ( i =< argc )
// because zero ( 0 ) is your program name.
while ( i < argc)
{
// then use argv for your data comparison
// or whatever you need to do with it
i++;
}
str to int is atoi function.
so what do you think sending i into your function will be giving it?
Code:
n=armstrongtest(i); // <-- i = what?
this is your first time using argc, and argv isn't it?
run this program putting values or typing stilly stuff on your command line to see what argc and argv are used for.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main (int argc, const char **argv)
{
int i = 0;
for ( i = 0; i < argc; i++)
printf("argc = %d ; argv = %s\n", i, argv[i]);
return 0 ;
}
when a function does a return it exits that function so your function ending can be written like this as well
Code:
if(p1 == result) {
return 1;
}
else
{
return 0;
}
// your compiler might complain so maybe you'll
// have to still add this even though it should not even reach here
return -1 ; to check if return == -1 it failed , or whatever your heart desires.
}
but if I just happened to get your logic backwards, str to int is atoi(str);
Code:
while(i<= atoi(argv[1]))
google say these are some of the Armstrong numbers whereas 10 is not one of them, as well as something else I pointed out about what you're sending in your function.
my results I get are:
Code:
userx@slackwhere:~/bin
$ ./temp 10
The number 0 is an Armstrong number, and it has 0 algarisms.
The -digit
numbers equal to the sum of th powers of
their digits (a finite sequence) are called
Armstrong numbers or plus perfect
number and are given by 1, 2, 3, 4, 5, 6, 7, 8, 9, 153, 370, 371, 407, 1634, 8208, 9474, 54748, ... (OEIS A005188).
just so you know what is ahead of you.