I'm trying to read a single character into a char* called val and when I use scanf() it returns null. Here is my code:
#include <stdio.h>
int main(int argc, char *argv[])
{
char *val;
if (argc == 2)
{
val = argv[1];
}
else
{
scanf("%s", val);
}
printf("Val = %s", val);
}
If I try to use malloc(), it will continuously read from standard input if the input is one character long, which is how long I want my input to be.