Hello once more,
I suspect that I may be again overlooking something simple, but for some reason my code is outputting gibberish when it should be simply using a function to take two arguments (a char and an int) and printing the char to the same value of the int, e.g. entering 'a' and '5' should produce "aaaaa".
Code:
#include <stdio.h>
void char_times_int(char ch, int num);
int main(void)
{
int num;
char ch;
printf("Enter a number, then a character.\n");
scanf("%d %c", &num, ch);
char_times_int(ch, num);
getchar();
getchar();
return 0;
}
void char_times_int(char ch, int num)
{
int count;
for (count = 1; count <= num; count++)
putchar(ch);
}
If I remove the printf/scanf and simply define num = 5 and ch = 'a' then it works fine, but the iteration requires user input.
Any help much appreciated whilst I hang my head in shame.
Cheers,
Twazzler