c keyboard input code example
Example 1: c user input
int main()
{
char chr;
printf("Enter a character: ");
scanf("%c",&chr);
printf("You entered %c.", chr);
return 0;
}
Example 2: c user input
int main()
{
int testInteger;
printf("Enter an integer: ");
scanf("%d", &testInteger);
printf("Number = %d",testInteger);
return 0;
}
Example 3: read from stdin c
int main( ) {
char str[100];
int i;
printf( "Enter a value :");
scanf("%s %d", str, &i);
printf( "\nYou entered: %s %d ", str, i);
return 0;
}
Example 4: read a document from console in c
int main(int argc,char *argv[]){
FILE *in=fopen(*++argv,"r");
char c;
while((c=fgetc(in))!=EOF)
putchar(c);
fclose(in);
return 0;
}