Question

In: Computer Science

Create program which verifies if input string is a valid variable declaration or not. Use C...

Create program which verifies if input string is a valid variable declaration or not. Use C programming language.

- This program can only use the following variable types: char, float, and int

- Remove any newline \n from input string

- The input prompt should say ">>> "

- If input declaration is valid, it should print "Valid dec\n"

- If input declaration is invalid, it should print "Invalid dec\n"

- Make sure the identifier entered matches the rules of C identifiers

- No need to worry about value assignments (Ex. int i = 0;)

Example Runs:

• Invalid identifier.

    >>> char 3var;
    Invalid dec

• Invalid type.

    >>> double my_var;
    Invalid dec

• Valid declaration.

    >>> int my_int;
    Valid dec

Solutions

Expert Solution

Code:

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char string[25];
int count=0,flag;
printf("enter any string: ");
scanf("%s",string);
printf(">>>",string);
if((string[0]>='a'&&string[0]<='z')||(string[0]>='A'&&string[0]<='Z')||(string[0]=='_'))
{
for(int i=1;i<=strlen(string);i++)

{
if((string[i]>='a'&& string[i]<='z')||(string[i]>='A' && string[i]<='Z')||(string[i]>='0'&& string[i]<='9')

||(string[i]=='-')){
count++;
}}

if(count==strlen(string))
{
flag=0;
}
  
}
else
{
flag=1;
}
if(flag==1)

printf("Invalid dec\n");
else
printf("Valid dec\n");
}

Note:***I hope your happy with my answer***If you have any doubts please comment me****Thank you....


Related Solutions

Using C++ Create a program that asks the user to input a string value and then...
Using C++ Create a program that asks the user to input a string value and then outputs the string in the Pig Latin form. - If the string begins with a vowel, add the string "-way" at the end of the string. For “eye”, it will be “eye-way”. - If the string does not begin with a vowel, first add "-" at the end of the string. Then rotate the string one character at a time; that is, move the...
use C++ Write a program to calculate the frequency of every letter in an input string...
use C++ Write a program to calculate the frequency of every letter in an input string s. Your program should be able to input a string. Calculate the frequency of each element in the string and store the results Your program should be able to print each letter and its respective frequency. Identify the letter with the highest frequency in your message. Your message should be constructed from at least 50 letters. Example of Output: letters frequency a 10 b...
A C program that will perform the following: Input the string: Abc_3_deF Expected Output: The string...
A C program that will perform the following: Input the string: Abc_3_deF Expected Output: The string you entered is: aBC_Three_DEf An output for just this specific input will be fine. If you want to provide a program for all outputs, it would help with my understanding of how the program works overall as well but it is not needed. Thanks!
Write a Python program which prompts the user to input a string. Then, print the string...
Write a Python program which prompts the user to input a string. Then, print the string in reverse to the terminal Sample output Please enter a word: "zeus" The reverse of zeus is suez Hint: There are several ways to accomplish this. Recall that a string is an itterable object and therefore can be used with a for loop
Indicate which of the following are valid C++ variable names and which are not. If not,...
Indicate which of the following are valid C++ variable names and which are not. If not, state the reason the name is invalid. Variable Name Valid – Yes/No If Invalid – Reason income 2time int Tom's two fold c3po income#1 item
C++ Write a program that takes a string and integer as input, and outputs a sentence...
C++ Write a program that takes a string and integer as input, and outputs a sentence using those items as below. The program repeats until the input string is "quit". If the input is: apples 5 shoes 2 quit 0 the output is: Eating 5 apples a day keeps your doctor away. Eating 2 shoes a day keeps your doctor away.
Write a basic C++ program with function, whose input is a character and a string, and...
Write a basic C++ program with function, whose input is a character and a string, and whose output indicates the number of times the character appears in the string. Ex: If the input is: n Monday the output is: 1 Ex: If the input is: z Today is Monday the output is: 0 Ex: If the input is: n It's a sunny day the output is: 2 Case matters. n is different than N. Ex: If the input is: n...
Write a program to create a tree randomly. You can use C++ programming language. The input...
Write a program to create a tree randomly. You can use C++ programming language. The input is the number of vertices in the tree, and the output is an adjacent list of the tree. (Managed to complete this assignment with a binary tree. But, was told I needed a general tree instead)
Create a c++ program with this requirements: Create an input file using notepad ( .txt )...
Create a c++ program with this requirements: Create an input file using notepad ( .txt ) . When testing your program using different input files, you must change the filename inside your program otherwise there will be syntax errors. There are a finite number of lines to be read from the data file. But we can’t assume to know how many before the program executes; so, the standard tactic is to keep reading until you find the “End of File”...
In objective-C Task: Write a program whose input is a character and a string, and whose...
In objective-C Task: Write a program whose input is a character and a string, and whose output indicates the number of times the character appears in the string. The output should include the input character and use the plural form, n's, if the number of times the characters appears is not exactly 1.You may assume that the string does not contain spaces and will always contain less than 50 characters. Ex: If the input is: n Monday the output is:...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT