Skip to content

Instantly share code, notes, and snippets.

@thetekst
Created June 29, 2012 14:17
Show Gist options
  • Save thetekst/3018221 to your computer and use it in GitHub Desktop.
Save thetekst/3018221 to your computer and use it in GitHub Desktop.
Input int, char, getchar()
//Input int
#include <stdio.h>
int main(int argc, char const *argv[])
{
int dec;
printf("Input: ");
scanf("%d", &dec);
printf("%d", dec);
return 0;
}
//Input char
#include <stdio.h>
int main(int argc, char const *argv[])
{
char str[20];
printf("Input: ");
scanf("%s", &str);
printf("%s", str);
return 0;
}
//Input getchar()
#include <stdio.h>
int main(int argc, char const *argv[])
{
char c;
printf("Input: ");
while((c=getchar())!='\n')
{
printf("%c",c);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment