C Programming. Given the following code, complete the task. #include #include in
ID: 3907796 • Letter: C
Question
C Programming. Given the following code, complete the task.
#include
#include
int main()
{
int degree;
char c[20], weekday[20], dtm[100];
strcpy( dtm, "Saturday * weather 79" );
sscanf( dtm, "%s * %s %d", weekday, c, °ree );
return(0);
}
I would like to print a message "Invalid line" when
1) the degree is missing, for example, let's say string is "Saturday * weather ".
2) degree is not a number, for example, string is "Saturday * weather nt"
3) additional information is provided after the degree, for example, string is "Saturday * weather 79 89 21"(79 is the degree)
4) * is missing.
Explanation / Answer
#include #include int main() { int degree; char c[20], weekday[20], dtm[100]; strcpy(dtm, "Saturday * weather 79"); if(sscanf(dtm, "%s * %s %d", weekday, c, °ree) < 3) { printf("Invalid line "); } return (0); }Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.