(C language)

Hi.. Can anyone write a function to accept a character and display it 10 times??

Thanks in advance..

Recommended Answers

All 8 Replies

Sorry but we don't write code here for you, that's the rule

So I'll give a suggestion instead to get you started
...create a loop in the function that will print out the character 10 times
if you have problems with the code then post it here

(C language)

Hi.. Can anyone write a function to accept a character and display it 10 times??

Thanks in advance..

#include<stdio.h>
main()
{
char a;
int i;
printf("\tEnter a character:\t");
scanf("%d", &a);
fflush(stdin);
for(i=0;i<10;i++)
{
printf("%s", &a);
}
}


Please correct the above program, it displays only once, i want it to display 10 times, what mistake have i done????

Use CODE Tags!!!

char a;            // define a character
scanf("%d", &a);   // read an INTEGER into the character
printf("%s", &a);  // print the character as a STRING

You tell Us what's wrong with the code...

When you do "scanf("%c", &a);" you save only one character, so you can't use "printf("%s", &a);" to display the character saved in "a", if you execute this code, a segfault might append. To display the caracter in "a", you have to use "printf("%c", a);".

Hey passionated, you should only log in under one username. You should not use the savoie username too, especially in the same thread.

Hey WaltP, I just tryed to help passionated, we are not the same user.

Maybe so, but I was asking passionated so he can learn something, not to have the questions answered by someone else so he doesn't have to think. Just sayin'.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.