Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int main () {
- char message [] = "";
- char code [] = "";
- int splittedCode [] = {};
- int digit, digitNumber;
- // Get message
- printf ("Scrivi un messaggio.\n");
- scanf ("%s", message);
- //Get code
- printf ("Inserisci il codice segreto (massimo 6 numeri).\n");
- scanf ("%s", &code);
- //Check if code contains letters
- for (int i = 0; i < strlen (code); ++i) {
- digit = code [i];
- if (digit >= "0" && digit <= "9") {
- ++digitNumber;
- }
- }
- //If code contains letter or is more than 6 characters long
- while (digitNumber != strlen (code)) {
- printf ("Il codice non e' valido, inserisci un codice valido.\n");
- scanf ("%d", &code);
- for (int i = 0; i < strlen (code); ++i) {
- digit = code [i];
- if (digit >= "0" && digit <= "9") {
- digitNumber = 0;
- ++digitNumber;
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement