input string in c code example
Example 1: c input output
#include <stdio.h>
int main()
{
int testInteger;
printf("Enter an integer: ");
scanf("%d", &testInteger);
printf("Number = %d",testInteger);
return 0;
}
Example 2: how to store a user input with spaces in c
#include <stdio.h>
int main(){
char name[20];
printf("Enter a name : ");
scanf("%[^\n]%*c", &name);
printf("the name entered is: %s\n", name);
return 0;
}
Example 3: c user input
#include <stdio.h>
int main()
{
char chr;
printf("Enter a character: ");
scanf("%c",&chr);
printf("You entered %c.", chr);
return 0;
}
Example 4: getting string input in c
#include<stdio.h>
#include<conio.h>
void main(){
chat sam[10];
clrscr();
printf("ENTER STRING NAME :");
gets(s);
printf("STRING :%s",s);
getch();
}
Example 5: Syntax To Take Input In C
Integer: Input: scanf("%d", &intVariable); Output: printf("%d", intVariable);
Float: Input: scanf("%f", &floatVariable); Output: printf("%f", floatVariable);
Character: Input: scanf("%c", &charVariable); Output: printf("%c", charVariable);
Example 6: input output string in c
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main()
{
char ch;
char s[100];
char p [100];
scanf("%c", &ch);
scanf("%s", s);
scanf("\n");
scanf("%[^\n]%*c", p);
printf("%c \n", ch);
printf("%s \n", s);
printf("%s", p);
return 0;
}