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...
Write a C++ Program Write a program that prompts the user to input a string. The...
Write a C++ Program Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. You must insert the following comments at the beginning...
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!
C++ Only Create a function named PrintStudents, which takes a string input filename and an integer...
C++ Only Create a function named PrintStudents, which takes a string input filename and an integer minimum score value and a string output file name as a parameters. The function will read the student scores and names from the file and output the names of the students with scores greater than or equal to the value given. This function returns the integer number of entries read from the file. If the input file cannot be opened, return -1 and do...
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
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
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)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT