Hello all, I just finished up this vertical histogram (finally lol).
My question is this, is it possible to change out the non incremented elements (basically any number in the array that is a 0), with either a blank character or a null?
I've tried a lot of the same things that work with char arrays..
Code:
arrxy[y][x]=(arrxy[y][x]=='0') ? '\0' : arrxy[y][x];
Also tried the same thing with if statements. Is it even possible to blot out the 0's?
Here's the code, not well notated because most of it planned out beforehand in notepad. I wrote where the ternary statements and if's were, in the bottom for loop:
Code:
#include<stdio.h>
main()
{
int arrxy[12][10];
char lookgood;
int c, scan;
int y, x;
int num[9]={0};
for(y=0; y<=11; ++y){
for(x=0; x<=9; ++x){
arrxy[y][x]=0;
}
}
while ((c=getchar())!=EOF){
switch (c) {
case '0':{
num[0]=(c=='0')? --num[0] : num[0];
arrxy[num[0]+12][c-'0']++;
break;
}
case '1':{
num[1]=(c=='1')? --num[1] : num[1];
arrxy[num[1]+12][c-'0']++;
break;
}
case '2':{
num[2]=(c=='2')? --num[2] : num[2];
arrxy[num[2]+12][c-'0']++;
break;
}
case '3':{
num[3]=(c=='3')? --num[3] : num[3];
arrxy[num[3]+12][c-'0']++;
break;
}
case '4':{
num[4]=(c=='4')? --num[4] : num[4];
arrxy[num[4]+12][c-'0']++;
break;
}
case '5':{
num[5]=(c=='5')? --num[5] : num[5];
arrxy[num[5]+12][c-'0']++;
break;
}
case '6':{
num[6]=(c=='6')? --num[6] : num[6];
arrxy[num[6]+12][c-'0']++;
break;
}
case '7':{
num[7]=(c=='7')? --num[7] : num[7];
arrxy[num[7]+12][c-'0']++;
break;
}
case '8':{
num[8]=(c=='8')? --num[8]: num[8];
arrxy[num[8]+12][c-'0']++;
break;
}
case '9':{
num[9]=(c=='9')? --num[9] : num[9];
arrxy[num[9]+12][c-'0']++;
break;
}
break;
}
}
for (y=0; y<=11; ++y){
for(x=0; x<=9; ++x){
/** arrxy[y][x]=(arrxy[y][x]=='0') ? '\0' : arrxy[y][x] ;
Also tried if statements, both with and without constant
character indicators ' ' **/
printf("%d%c", arrxy[y][x], lookgood=(x==9) ? '\n': ' ');
}
}
printf("====================\n0 1 2 3 4 5 6 7 8 9");
}