I'm trying to use putchar() and getchar() to read in a string of characters from the user, and then my loop will print each character three times, print a new line, etc etc, until every character in the variable "userInput" has been printed. When I try to compile my program I receive the following errors:
warning: assignment makes pointer from integer without a cast [enabled by default]
userInput = getchar();
^
warning: comparison between pointer and integer [enabled by default]
while(counter < strlen(userInput))
^
error: array subscript is not an integer
putchar(userInput[counter]);
^
error: array subscript is not an integer
putchar(userInput[counter]);
^
error: array subscript is not an integer
putchar(userInput[counter]);
^
How can I fix these errors? I'm new to C and can't figure out what it means by the pointer cast error, and why my counter variable isn't working.
My code is as follows:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main(void)
{
char *userInput;
int *counter = 0;
printf("Enter a string of characters: ");
userInput = getchar();
while(counter < strlen(userInput))
{
putchar(userInput[counter]);
putchar(userInput[counter]);
putchar(userInput[counter]);
printf("\n");
counter++;
}
}