hi this is a course work question and i have tried multiple methods to get it to work so if you can show me where i'm going wrong i would greatly appreciate it.
i have to read a 4 character input and create each of the numbers into a sort of ascii version of it you will see below.
my current output doesn't generate a usable output but if you take away the RETURN j from each of the if statements and the printf(j) at the bottom it produces the correct output but vertically i need them horizontal. thats why i was trying to put them into another array to output them side by side.
/*
Algorithm
scan for input
when user enters characters read characters into variable
check if string is alpha if so display message
check the length of the string if greater than 4 characters display message
check if numeric characters
loop through checking which characters have been entered
return function output to variable
display contents of variable
*/
#include<stdio.h>
#include<string.h>
#include<ctype.h>
int main()
{
char numberString[5];
int i = 0;
int j[5];
scanf("%s", numberString);
if(isalpha(numberString))
{
printf("i can only take numeric values");
}
else if(strlen(numberString) > 4)
{
printf("i can only accept 4 characters sorry");
}
else if(isdigit(numberString))
{
for ( i = 0; i < 4; ++i )
{
if ( numberString[i] == '0' )
{
printf(" 000\n");
printf(" 0 0\n");
printf("0 0\n");
printf("0 0\n");
printf("0 0\n");
printf(" 0 0\n");
printf(" 000");
return j;
}
else if ( numberString[i] == '1')
{
printf(" 0\n");
printf("00\n");
printf(" 0\n");
printf(" 0\n");
printf(" 0\n");
printf("000");
return j;
}
else if ( numberString[i] == '2')
{
printf(" 000\n");
printf("0 0\n");
printf(" 0\n");
printf(" 0\n");
printf(" 0\n");
printf("0\n");
printf("0000");
return j;
}
else if ( numberString[i] == '3')
{
printf(" 000\n");
printf("0 0\n");
printf(" 0\n");
printf(" 00\n");
printf(" 0\n");
printf("0 0\n");
printf(" 000");
return j;
}
else if ( numberString[i] == '4')
{
printf("0\n");
printf("0\n");
printf("0\n");
printf("0\n");
printf("0 0\n");
printf("000000\n");
printf(" 0");
return j;
}
else if ( numberString[i] == '5')
{
printf("000000\n");
printf("0\n");
printf("0\n");
printf("0000\n");
printf(" 0\n");
printf(" 0\n");
printf("0000");
return j;
}
else if ( numberString[i] == '6')
{
printf("000000\n");
printf("0\n");
printf("0\n");
printf("000000\n");
printf("0 0\n");
printf("0 0\n");
printf("000000");
return j;
}
else if ( numberString[i] == '7')
{
printf("000000\n");
printf(" 0\n");
printf(" 0\n");
printf(" 0\n");
printf(" 0\n");
printf("0\n");
printf("0");
return j;
}
else if ( numberString[i] == '8')
{
printf(" 00 \n");
printf(" 0 0\n");
printf("0 0\n");
printf(" 0000 \n");
printf("0 0\n");
printf(" 0 0\n");
printf(" 00");
return j;
}
else if ( numberString[i] == '9')
{
printf("00000\n");
printf("0 0\n");
printf("0 0\n");
printf("00000\n");
printf(" 0\n");
printf(" 0\n");
printf(" 0");
return j;
}
}
}
printf(j);
}