Question: Use C language Write a program to determine whether a given string with no white space characters is a valid C identifier. The input to

Use C language

Write a program to determine whether a given string with no white space characters is a valid C identifier. The input to the program will be a number of lines, each of which contains a string, which you can assume has no white space characters before the new line at the end of the line. Your program should scan the string, character by character, using getchar(), and determine if it is a valid C identifier, based on the rules discussed in class, and covered in the class slides. Keep in mind that, although identifiers which begin with an underscore are not used by user application programs in C by convention, they are valid C identifiers, so your program should accept them.

There will be 5 strings in the input. For each of these strings, after determining whether it is a valid C identifier or not, your program should print out either Valid or Invalid, followed by a new line (that is, each Valid or Invalid result will be printed on a separate line in

the output).

Suppose the following input:

_Number1 1_2_3 total

Num1+Num2 big_number!

The output should be: Valid

Invalid Valid Invalid Invalid

Your program can use either if statements or switch statements for much of the algorithm. You CANNOT use C library functions such as isalpha() or isdigit(), which we will see later

Also keep in mind that you may need to consume remaining characters on the line after determining that a given line of input contains an invalid identifier.

CONSTRAINTS:

You cannot use arrays of any kind (including strings).

You CANNOT use C library functions other than getchar() and printf().

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!