Created
August 8, 2019 22:15
-
-
Save gotjon05/1ac1da832d0c5b6a6c06e9aa67eb7fef to your computer and use it in GitHub Desktop.
write a program to print a histogram of lengths of words in its input. Draw histogram with bars horizontal and vertical.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#define MAXLINE 20 | |
int getlines(char line[], int maxline); | |
void print_array(char line[], int maxline, int array_size); | |
int main() | |
{ | |
int array_size; | |
char line[MAXLINE]; | |
while(array_size = getlines(line, MAXLINE)){ | |
//printf("%s %d", line, array_size); | |
print_array(line, MAXLINE, array_size); | |
} | |
} | |
int getlines(char line[], int maxline) | |
{ | |
int c, i; | |
for(i = 0; i < maxline-1 && (c = getchar()) != EOF && c != '\n'; i++){ | |
line[i] = c; | |
} | |
line[i] = '\0'; | |
return i; | |
} | |
void print_array(char line[], int maxline, int array_size) | |
{ | |
int i; | |
for(i=0; i < maxline; ++i){ | |
printf("%s, %d", line, array_size); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment