C Programming Strings
C Programming Strings
char s[5];
String Declaration in C
#include <stdio.h>
int main()
{
char name[20];
printf("Enter name: ");
scanf("%s", name);
printf("Your name is %s.", name);
return 0;
}
Output
You can use the fgets() function to read a line of string. And, you can
use puts() to display the string.
#include <stdio.h>
int main()
{
char name[30];
printf("Enter name: ");
fgets(name, sizeof(name), stdin); // read string
printf("Name: ");
puts(name); // display string
return 0;
}
Output
Here, we have used fgets() function to read a string from the user.
fgets(name, sizeof(name), stdlin); // read string
Note: The gets() function can also be to take input from the user. However,
it is removed from the C standard.
It's because gets() allows you to input any length of characters. Hence,
there might be a buffer overflow.
#include <stdio.h>
int main() {
char str[1000], ch;
int count = 0;
#include <stdio.h>
int main() {
char line[150];
int vowels, consonant, digit, space;