0

Is it possible to create a program that takes a user's input and checks it against a formatted array and then ensures user's input complies with this format.

char password[8]
password[0] = 'A, B, C , D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z'
password[1] = '!, ", £, $, %,^, &, *,(, )'
password[2] = '!, ", £, $, %,^, &, *,(, )'
password[3] = '1,2,3,4,5,6,7,8,9,0'
password[4] = '1,2,3,4,5,6,7,8,9,0'
password[5] = '1,2,3,4,5,6,7,8,9,0'
password[6] = 'a, b, c , d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z'
password[7] = 'a, b, c , d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z'

In my code I'm trying to take a user's input and put it into this character array and ensure that the user's input is only 8 characters long whilst each character of the input has to be one of these specified characters for example the first character of the input must be a uppercase A-Z.

Sorry if this is super wrong or doesn't make sense I'm new to programming

J52677
  • 11

1 Answers1

0

Super welcome to stack overflow community.

So what I am gathering from your question is you want to validate input provided via console in this case.

Yes you can do so. There is not fixed way to do this, and you may want to mix up different approaches as and when required.

Lets see two cases that you have mentioned in your problem

  • I/P Length validation
  • I/P starts with Uppercase letter

Both these can be validated using a regular expression (regex for short).

You can look into regex and how to use it in C in stack overflow ans.

A valid regex to fulfill both cases can be ^[A-Z].{7}$, which enforces first letter starts with any among uppercase alphabet letters of length 1, and then any characters of 7 length. Hence total length of string being 8.

For checking more on regex patterns and testing your regex you can visit this & this

Ayush
  • 130
  • 1
  • 8