Make a simple function called printASCII() that prints the entire ASCII table. T
ID: 3698324 • Letter: M
Question
Make a simple function called printASCII() that prints the entire ASCII table. The function does not take any parameters and does not return a value. Remember that a character is stored in 1 byte of information and therefore there are 256 possible values (from 0 to 255). Use a for loop to loop through each value and print it as a character with the %c printf modifier. Use a function prototype above main( ), and then write the function body below main().
* Please use C or C++ using (printf, scanf) or (cin, cout)*
Thank you!
Explanation / Answer
For the above question a simple for loop is used that is like below
int main(){
int i;
for(i=0;i<=255;i++)
printf("ASCII value of character %c: %d ",i,i);
return 0;
}
it prints the ASCII codes from 0 to 255.
All identifiers in C need to be declared before they are used. This is true for functions as well as variables. For functions the declaration needs to be before the first call of the function. A full declaration includes the return type and the number and type of the arguments. This is also called the function prototype.
#include <stdio.h>
int printASCII(int);
int main (void)
{
int i;
for (i = 0; i < 256; i++) {
printf("%c ", ch);
ch = ch + 1;
return 0;
}
}
int printASCII(int i)
{
return ch;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.