countLines function
- String txt
Implementation
int countLines(String txt) {
// Initialize a counter variable to store the number of lines.
int count = 0;
// Loop through each character in the string.
for (int i = 0; i < txt.length; i++) {
// If the character is a newline character, increment the counter.
if (txt[i] == '\n') {
count++;
}
}
// Return the counter value.
return count;
}