This is not what I want to look like the sample input output how can I change th
ID: 3783136 • Letter: T
Question
This is not what I want to look like the sample input output
how can I change this to read several line input together at once and then output the result in many line at once?
Use C language
Use Stdio.h
CONSTRAINTS:
You cannot use arrays of any kind (including strings).
You CANNOT use C library functions other than getchar() and printf().
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.
thirdweek thirdweek third week gcc identifirecheck.c thirdweek /a.out Enter inden fire: pravesh 12 Valid Enter indenfire pravesh12 Valid Enter indenfire +pravesh12 Invalid Enter inden fire: 123pravesh Invalid Enter indenfire 123prav Valid thirdweekExplanation / Answer
For reading several line inputs together at once:-
char ch;
int i=0;
printf("Enter the 5 inputstrings, press enter for next string- ");
while(i<5)
{
while((ch = getchar())!=' ')
{
/*Write the condition for checking and assigning values*/
}
i++ ;
}
this is the C code for reading multiple lines without using array.
Now you can perform the check operation to find whether the strings are valid and invalid identifier.
For that, you have to assign 5 variables (or same no. of variables equal to total no. of input strings) and initialize them to the value -1. Then assign flag value for two cases( for eg, 1 for valid, 0 for invalid). Now while checking if you get valid or invalid, you have to specifically check which variables are valued -1 or not. If its not -1 then assign them to 1 or 0 as per the case respectively.
So if a=1,b=0,c=-1,d=-1,e=-1 then assign 0 or 1 to c. You have to do this in the comment section which is provided in the input code above.
Now for the output just print valid for 1 and invalid for 0 respectively to the variables.
So, its simple, but line of codes will be maximum.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.