Skip to main content
Search
Search This Blog
Livecodo
Pages
Home
Courses
Blog
About us
More…
Share
Get link
Facebook
X
Pinterest
Email
Other Apps
March 28, 2024
Write a c program to take multiline string input and print individual string length .
#include
#include
#define MAX_STRINGS 10 #define MAX_LENGTH 100 int main() { 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; }
Popular Posts
March 26, 2024
Dynamic Memory allocation in C
May 18, 2024
Searching and sorting Algorithm in C