The following question assume the file test contains comma-delimited digits on s
ID: 3644671 • Letter: T
Question
The following question assume the file test contains comma-delimited digits on separatelines as follows:
4,7,1,2,7
1,8,3
1,2,8,3,4,7,9,4,1,0
Thus each line contains a list of single digits separated by comma.
Write a program that validates a sequence of digits in the CSV format (given above) i.e. each
line of the input text of the program contains comma-separated list of digits. The output value
1 indicates that the input text file is valid and the output value 0 indicates that the input text
file is invalid. You must use C programming language and the corresponding source code
must be in the file p1.c.
For example:
$p1 < test
1
Explanation / Answer
#include #include int main() { int c; while ((c = getchar()) != EOF ) { switch(c) { case'0': printf("1"); break; case'1': printf("1"); break; case'2': printf("1"); break; case'3': printf("1"); break; case'4': printf("1"); break; case'5': printf("1"); break; case'6': printf("1"); break; case'7': printf("1"); break; case'8': printf("1"); break; case'9': printf("1"); break; case',' : printf("1"); break; case' ' : printf("1"); break; default : printf("0"); break; } }Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.