How to make multiple input for this program? Since i already limit the array to 50, i would like to have more input for it..
#include<stdio.h>
#define MaxAry 50
int init_int(int iAry[], int iNum);
void modify_int(int iAry[]);
int main(void)
{
int input;
int iAry[MaxAry];
int i;
int iNum;
iNum = init_int(iAry, iNum);
modify_int(iAry);
for (i = 0; i < iNum; i++)
{
printf("The output number at input %02d is %d\n", i + 1, iAry[i]);
}
}
int init_int(int iAry[], int intNum)
{
for (intNum = 0; intNum < MaxAry; intNum++)
{
printf("Enter number %02d :", intNum+1);
scanf("%d", &iAry[intNum]);
intNum++;
return intNum;
}
}
void modify_int(int iAry[])
{
int i;
for (i = 0; i < MaxAry; i++)
{
iAry[i] += 32;
}
}
Either that, or use a ridiculously long array. 1024 would usually work if you know the input will be limited.
Don't store input in ints. Store it in chars or wchar_ts if you need Unicode.
This is what I have updated from the previous code..
The function for integer looks fine, but it doenst work well for the character function.. I couldnt find where the fault is...
And one more thing is the MaxAry that i have limited on it doesnt seems to have any use.. improvement needed.. Any advice???
#include<stdio.h>
#define MaxAry 50
int init_int(int iAry[], int intNum);
void modify_int(int iAry[]);
int init_char(char cAry[], int charNum);
void modify_char(char cAry[]);
int main(void)
{
int iAry[MaxAry];
char cAry[MaxAry];
int i;
int iNum;
int cNum;
iNum = init_int(iAry, iNum);
modify_int(iAry);
for (i = 0; i < iNum; i++)
{
printf("The output number at input %02d is %d\n", i + 1, iAry[i]);
}
cNum = init_char(cAry, cNum);
modify_char(cAry);
for (i = 0; i < cNum; i++)
{
printf("The output alphabet at input %02d is %c\n", i + 1, cAry[i]);
}
}
int init_int(int iAry[], int intNum)
{
int size;
printf("Enter the number of input you wish to put:\n");
scanf("%d", &size);
for (intNum = 0; intNum < size; intNum++)
{
printf("Enter number %02d :", intNum + 1);
scanf("%d", &iAry[intNum]);
}
return intNum;
}
void modify_int(int iAry[])
{
int i;
for (i = 0; i < MaxAry; i++)
{
iAry[i] += 32;
}
}
int init_char(char cAry[], int charNum)
{
int size;
printf("Enter the number of alphabet you wish to put:\n");
scanf("%d", &size);
for (charNum = 0; charNum < size; charNum++)
{
printf("Enter alphabet %02d : \n", charNum + 1);
scanf("%c", &cAry[charNum]);
}
return charNum;
}
void modify_char(char cAry[])
{
int i;
for (i = 0; i < MaxAry; i++)
{
cAry[i] += 32;
}
}