Hi, I'm new to C, but not programming in general, but am struggling to get my head around functions. I'm working my way through some C exercises to get some practice and have hit a wall. I need to use a function to take a number, such as 1, and print out One.
Here's what I've got so far:
Code:
#include <stdio.h>
int name(int n);
char numberOne[] = "One";
int main(void)
{
int n;
scanf("%d", &n);
if (n>=0 && n<10) name(n);
else printf("Error: number (%d) out of range\n", n);
}
int name(int n){
if(n == 1){
printf("%s", numberOne);
return 0;
}else{
printf("Got here");
return 0;
}
}
However, when I run the code and enter "1" the only thing that gets printed to the screen is "(lldb)". I've tried changing it to doing it without variables and just printing "One" but that gave the exact same result. I can't work out why this is, any help would be greatly appreciated.
Thanks!