-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck digit
More file actions
38 lines (36 loc) · 973 Bytes
/
check digit
File metadata and controls
38 lines (36 loc) · 973 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <cs50.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int main(int argc, string argv[])
{
// Check if 2 commandline arguments are given, otherwise abort program
if (argc == 2)
{
// Determine length of argv[1] to use as upper limit for for loop
int n = strlen(argv[1]);
// Loop through argv[1] to check if only numeric inputs are given, else abort program
for (int i = 0; i < n; i++)
{
if (isdigit(argv[1][i]))
{
printf ("%c\n", argv[1][i]);
printf ("Success\n");
}
else
{
printf ("Usage: ./ceasar key\n");
return 1;
}
}
}
else
{
printf ("Usage: ./ceasar key\n");
return 1;
};
// Transform argv[1] to int and assign to key variable
int key = atoi(argv[1]);
printf ("%i\n", key);
}