Introduction
C Programming
C Advanced
Important C Programs
Modal Box
Tutorials
C is a very powerful and widely used language. It is used in many scientific programming situations. It forms (or is the basis for) the core of the modern languages Java and C++. It allows you access to the bare bones of your computer.C++ is used for operating systems, games, embedded software, autonomous cars and medical technology, as well as many other applications. Don't forget to visit this section...
String in C
In C programming, a string is an array of characters terminated with a null character \0.
In C , array of character is declared as following :
char arrayname[size];
Single character may be taken as input by scanf function as ,
scanf(“%c”,&ch); where ch is the character variable.
If multiple characters has to enter as input , then instead of scanf in loop, gets function is used.
Syntax: gets(arrayname);
it automatically stores null at the last position of array.
Similarly, to print the string (char array), puts function may be used.
eg: puts(arrayname);
Program to take user's name as input and print it back.
#include <stdio.h> #include <conio.h> void main() { char name[20]; printf("enter your name\n"); gets(name); //function to accept the user entered string. printf("name entered by you :"); //n is used to display the value in new line. puts(name); }
Program to find length of the string and calculate the no of vowels in it.
#include <stdio.h> #include <conio.h> void main() { char str[50];
int i=0,count=0; printf("enter the string\n"); gets(str); //function to accept the user entered string. while(str[i]!=NULL)
{
if(str[i]=='a' || str[i]=='e' ||str[i]=='i' || str[i]=='o' ||str[i]=='u')
{
count++;
}
i++;
}
printf("length=%d , No of Vowels=%d",i,count);
}
Video/ C Introduction
Watch video in full size