Write this code using mbed.h Write a function that takes an integer N as input.
ID: 3607735 • Letter: W
Question
Write this code using mbed.h
Write a function that takes an integer N as input. Your function should print a line of * on the serial monitor of length N. For example, if input N is 5, print ***** on the serial monitor. Then move to the next line on the serial monitor.
In main(), test your function for all the values of N from 0 to 79. You’ll want to use a loop for this!
For this part, the writing of the function is worth 70%. Complete testing is worth 10%. Partial credit will be given for incomplete testing.
Sta
Explanation / Answer
#include <stdio.h>
FILE *ftr;
void printNStars(int n) {
for(int i=0;i<n;i++) {
fprintf(fptr, "*");
}
printf(" ");
}
// function to test the validity of string
// TESTS:
// check for the length of the string if all are stars
// if any character is not a star, return false
void testString() {
char str[200];
while(fgets(str, 100, fr) != NULL)
{
int stringLen = strlen(str);
for(int i=0;i<len;i++) {
if(str[i] != '*') {
return false;
}
}
}
return true;
}
int main(void) {
// test the function
f = fopen("output.txt", "rw");
for(int i=1;i<=79;i++) {
printNStars(i);
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.