3
submitted 3 months ago* (last edited 3 months ago) by akunohana@piefed.blahaj.zone to c/c_lang@programming.dev

Is there perhaps some other, better way to do it? Perhaps one with which clang doesn't give me "unused result" warnings?

MODS: If you deem it inappropriate for me to continuously ask for guidance here, please let me know. ๐Ÿ˜Š

#include <stdio.h>  

void executechoice(int choice);		
void printsavedpins(int pin_storage[]);  
void promptnewpin(void);  
void checkpinlength(int pin);  
void checkpinmatch(int pin);  
void updatepinstorage(int pin);  

int pin = 0;  
int pin_storage[10] = {0};  
int storage_index = 0;  
const int storage_limit = 10;  

//Prompt user for action.  
int main() {  

	int choice = 0;  
	printf("What would you like to do? (V)iew your saved pins, (S)ave a new pin or (E)xit? "); 
	while ((choice = getchar()) != EOF) {  
		getchar(); //clang gives 'unused result' warning but '\n' needs to be removed.  
		if (choice == 'E' || choice == 'e') { break; }  
		else {  
			executechoice(choice);  
			getchar(); //clang gives 'unused result' warning but '\n' needs to be removed.  
			printf("What would you like to do next? (V)iew your saved pins, (S)ave a new pin or (E)xit? ");  
		}  
	}  
	printf("Goodbye!\n");  
	return 0;  
}  

//Function definitions  
void executechoice(int choice) {		
	if (choice == 'V' || choice == 'v') { printsavedpins(pin_storage); }  
	else if (choice == 'S' || choice == 's') { promptnewpin(); }  
	else { printf("Invalid choice! What would you like to do? (V)iew your saved pins, (S)ave a new pin or (E)xit? "); }  
}  

void printsavedpins(int pin_storage[]) {  
	for (int i = 0; i < storage_limit; i++) printf("Pin %d: %d\n", i + 1, pin_storage[i]);  
}  

void promptnewpin(void) {  
	
	printf("Enter new pin: ");  
	scanf("%d", &pin);  
	checkpinlength(pin);  
}  

void checkpinlength(int pin) {  
	
	if (pin < 1000*100) {  
		printf("Pin has to be at least six digits!\n");  
		promptnewpin();  
	}  
	else checkpinmatch(pin);  
}  

void checkpinmatch(int pin) {  

	int check = 0;  
	printf("Verify your new pin: ");  
	scanf("%d", &check);  
	if (check != pin) {  
		printf("Mismatch! ");  
		promptnewpin();  
	}  
	else updatepinstorage(pin);  
}  

void updatepinstorage(int pin) {  

	pin_storage[storage_index] = pin;  
	storage_index++;  
	if (storage_index >= storage_limit) { storage_index = 0; }  
	printf("New pin saved successfully!\n");  
}  
you are viewing a single comment's thread
view the rest of the comments
[-] akunohana@piefed.blahaj.zone 1 points 3 months ago

Thanks! I'll look into it! ๐Ÿ˜Š

this post was submitted on 20 May 2026
3 points (100.0% liked)

C Programming Language

1343 readers
3 users here now

Welcome to the C community!

C is quirky, flawed, and an enormous success.
... When I read commentary about suggestions for where C should go, I often think back and give thanks that it wasn't developed under the advice of a worldwide crowd.
... The only way to learn a new programming language is by writing programs in it.

ยฉ Dennis Ritchie

๐ŸŒ https://en.cppreference.com/w/c

founded 3 years ago
MODERATORS