Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Creating A Database In Filemaker Pro Visual QuickProject Guide

Authors: Steven A. Schwartz

1st Edition

0321321219, 978-0321321213

More Books

Students also viewed these Databases questions