Skip to content

Instantly share code, notes, and snippets.

@gotjon05
Created August 8, 2019 22:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gotjon05/1ac1da832d0c5b6a6c06e9aa67eb7fef to your computer and use it in GitHub Desktop.
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.
#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