← Back to Codes
C
Multiline String Length
Reads multiple lines of input until a semicolon and calculates their lengths.
multiline_string_length.c
#include <stdio.h>
#include <string.h>
#define MAX_STRINGS 10
#define MAX_LENGTH 100
int main() {
printf("INSTRUCTIONS: Enter multiple lines of text. Type a semicolon ';' on a new line to finish input.\n");
char strings[MAX_STRINGS][MAX_LENGTH];
int string_count = 0;
char temp[MAX_LENGTH];
printf("Enter multiline string input, press enter key to input each string, end input with a semicolon:\n");
while (1) {
fgets(temp, MAX_LENGTH, stdin);
if (temp[strlen(temp) - 1] == '\n') {
temp[strlen(temp) - 1] = '\0';
}
if (strcmp(temp, ";") == 0) {
break;
}
strcpy(strings[string_count++], temp);
}
printf("\nIndividual string length results:\n");
for (int i = 0; i < string_count; i++) {
printf("String %d: Length %zu\n", i + 1, strlen(strings[i]));
}
return 0;
}Multiline String Length — Free C Code Example
Reads multiple lines of input until a semicolon and calculates their lengths. This free code example is available in C and can be copied and run immediately — no account or signup required. Use the language tabs above to switch between implementations.
How to Use This Code
- Select your language — click the language tab (C, Java, C++, or Python) above the code viewer.
- Copy the code — use the copy button in the top-right corner of the code block.
- Run it — paste into a file with the correct extension (.c, .java, .cpp, .py), compile, and run using your terminal or IDE.
- Follow the on-screen instructions in the terminal to provide any required inputs.
Frequently Asked Questions
What does this program do?
Reads multiple lines of input until a semicolon and calculates their lengths.
Which languages is it available in?
Available in C. Switch between implementations using the tabs at the top of the code viewer.
How do I run this code?
Copy the code, save it with the right file extension (.c, .java, .cpp, or .py), then compile or run it with your installed compiler or interpreter (GCC, JDK, G++, Python 3).
Is this code free?
Yes — free to view, copy, and use. No account required.