I just started coding, I wrote this code, it's exercise in book "C programing language", sorry that the code variables are not written in english, it seems that if number of words gets past 9, * and numbers below dont lineup, how can i fix that, and if you see better solution for code tell me,
Thanks.
#include <stdio.h>
#include <limits.h>
int main()
{
int c;
int flag=1;
int i;
int reci[100];
for(i=0; i<101; i++){
reci=0;
}
i=0;
while((c=getchar())!=EOF){
if(c==' ' || c=='\t' || c=='\n'){
i++;
flag=0;
}else flag=1;
if(flag==1){
reci++;
}
}
int maks=INT_MIN;
for(i=0; i<101; i++){
if(reci>maks){
maks=reci;
}
}
int j;
int linija=maks+1;
for(i=maks; i>=1; i--){
printf("%3d |", linija-=1);
for(j=0; j<101; j++){
if(reci[j]>=i){
printf(" *");
}else printf(" ");
}
printf("\n");
}
printf(" ");
for(i=0; i<101; i++){
if(reci>0){
printf("---");
}
}
printf("\n\t ");
for(i=0; i<101; i++){
if(reci>0){
printf("%d ", i+1);
}
}
return 0;
}
Thanks.
#include <stdio.h>
#include <limits.h>
int main()
{
int c;
int flag=1;
int i;
int reci[100];
for(i=0; i<101; i++){
reci=0;
}
i=0;
while((c=getchar())!=EOF){
if(c==' ' || c=='\t' || c=='\n'){
i++;
flag=0;
}else flag=1;
if(flag==1){
reci++;
}
}
int maks=INT_MIN;
for(i=0; i<101; i++){
if(reci>maks){
maks=reci;
}
}
int j;
int linija=maks+1;
for(i=maks; i>=1; i--){
printf("%3d |", linija-=1);
for(j=0; j<101; j++){
if(reci[j]>=i){
printf(" *");
}else printf(" ");
}
printf("\n");
}
printf(" ");
for(i=0; i<101; i++){
if(reci>0){
printf("---");
}
}
printf("\n\t ");
for(i=0; i<101; i++){
if(reci>0){
printf("%d ", i+1);
}
}
return 0;
}