# Thread: C Program Input Single 4 digit Hex Number Output Next 10 Hex Numbers Using Array

1. ## C Program Input Single 4 digit Hex Number Output Next 10 Hex Numbers Using Array

Beginner in C programming here and processing a small programming task here to help me understand a bit how hexadecimal numbers work in programming. Reading a book with an introduction to hexadecimals and other base counting methods used by computers. Trying to understand hexadecimals in C.

The small program below is supposed to accept input of a single hexadecimal number and output the next ten digits after it.

Example:
Input ABC1
Output ABC2, ABC3, ABC4, ABC5, ABC6, ABC7, ABC8, ABC9, ABCA, and ABCB.

Current output:

Enter the number ABC1
0001 0002 0003 0004 0005 0006 0007 0008 0009 000a

Obviously my current lack of understanding is keeping me from seeing the error in the code as I am new to counting in hex. I have tried several things, but this is the closest I've come so far.

Would anyone be so kind as to help me identify what I am doing wrong and advise what needs to be corrected? So that I may add it to my notes.

Code:
`#include <stdio.h>`
Code:
```
int main(void) {

int n, hexNum = { 0 };
int i, j;
printf("Enter the number ");
scanf("%hhhhx", &n);

for (j = 0; j<10; j++)
{

hexNum++;

for (i = 3; i>0; i--)
{
if (hexNum[i] == 16)
{
hexNum[i - 1]++;
hexNum[i] = 0;
}
}
printf("\n%x%x%x%x\n", hexNum, hexNum, hexNum, hexNum);

}
return 0;
}``` 2. How about starting with a really simple example.
Code:
```#include <stdio.h>

int main(void) {
int n;
printf("Enter hex number\n");
scanf("%x",&n);
printf("hex +1 = %x\n", n+1);
return 0;
}```
Code:
```\$ gcc foo.c
\$ ./a.out
Enter hex number
abc1
hex +1 = abc2
\$``` Popular pages Recent additions array, hex, input, number, output 