Skip to content

Instantly share code, notes, and snippets.

@pegvin
Created January 23, 2023 13:24
Show Gist options
  • Save pegvin/7568eff0c0ced0871c838d1ab7826bd5 to your computer and use it in GitHub Desktop.
Save pegvin/7568eff0c0ced0871c838d1ab7826bd5 to your computer and use it in GitHub Desktop.
Simple Function To Get A Single Digit From A Number At A Index
#include <stdlib.h>
#include <stdio.h>
int GetDigitAtIndex(int index, int num) {
int dig = 0, i = 0;
while(num > 0) {
dig = num % 10;
num = num / 10;
if (i == index) return dig;
i++;
}
return -1;
}
int main(void) {
int AppVersion = 364;
printf(
"Application Version %d.%d.%d\n",
GetDigitAtIndex(2, AppVersion),
GetDigitAtIndex(1, AppVersion),
GetDigitAtIndex(0, AppVersion)
);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment