Originally Posted by
SirSig
Edit:
I figured out my problem, it was that I am stupid. -_-
Please delete this thread.
Ahhh, sorry I did not know the proper etiquette. I realized my problem as soon as I posted it so I did not want to take up any body's time.
My code was:
Code:
/*-------------
Include Section
--------------*/
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
#include <time.h>
#define SIZE 10
/*------------------Main Functions------------------
Purpose: Prompts user to input integer
Returns: Signal to the OS
--------------------------------------------------*/
void sep_digits(long long int num);
void print_digits(int a[], int size);
int main(void) {
long long int input;
printf("Enter a positive integer or 0 (zero) to end: ");
scanf("%lld", &input);
while (input != 0) {
if (input < 0) {
printf("\nWrong input\n");
}
else {
sep_digits(input);
}
printf("\nEnter a positive integer or 0 (zero) to end: ");
scanf("%lld", &input);
}
printf("\n*** Program Terminated ***\n");
return(EXIT_SUCCESS);
}
/*------------------Seperate Digits Functions------------------
Purpose: Seperates and counts the numbers in the user's input.
Returns: Seperated and counted value.
--------------------------------------------------*/
void sep_digits(long long int num) {
int a[SIZE] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int digit, i;
while (num > 0) { // num has the value of user input
digit = num % 10;
a[digit] = a[digit] + 1;
num = num / 10;
}
print_digits(a, SIZE);
}
/*------------------Print Digits Functions------------------
Purpose: Prints output.
Returns: Prints output of the sep_digit function to the user in a formatted orientation.
--------------------------------------------------*/
void print_digits(int a[], int size) {
int i;
printf("\n\n");
printf("Digits: 0 1 2 3 4 5 6 7 8 9\n");
printf("Occurrences: ");
for (i = 0; i < 10; i++) {
printf(" %d",a[i]);
}
printf("\n");
}
except for at this while loop:
Code:
while (num > 0) { // num has the value of user input
digit = num % 10;
a[digit] = a[digit] + 1;
num = num / 10;
}
I had improperly put the a[digit] increment in a way so that it did not actually increment a[digit] this causing no change.