Coming back to programming after a number of years, currently fiddling with a simple version of Euclid's algorithm. It currently works if I assign values to the integers within the program, so I'm assuming that the issue lies with how I'm passing the integers from the command line.
Any help would be greatly appreciated.
#include <stdio.h>
//Defining variables
int x,y, rem;
//Defining function gcd
int gcd(int x, int y);
//Where x>= y and y>=0
int main(int argc, char *argv[])
{
//Read in command line arguments
x= sscanf(argv[1], "%d", &x);
y= sscanf(argv[2], "%d", &y);
gcd(x,y);
}
//Define recursive gcd function
int gcd(int x, int y)
{
while(y !=0)
{
rem=x%y;
x=y;
y=rem;
gcd(x,y);
}
return x;
}
man sscanfwill help you.gcd(x,y);inint gcd(int x, int y)appears to serve no purpose.