how to learn c programming in telugu
The C library function int puts(const char *str) writes a string to stdout up to but not including the null character. A newline character is appended to the output.
The C library function char *gets(char *str) reads a line from stdin and stores it into the string pointed to by str.It stops when either the newline character is read or when the end-of-file is reached, whichever comes first.
String variable c can only take a word. It is beacause when white space is encountered, the scanf()
function terminates.
Write a C program to illustrate how to read string from terminal.
#include <stdio.h>
int main(){
char name[20];
printf("Enter name: ");
scanf("%s",name);
printf("Your name is %s.",name);
return 0;
}
Output
Enter name: Dennis Ritchie Your name is Dennis.
Here, program will ignore Ritchie because, scanf()
function takes only string before the white space.
Reading a line of text
C program to read line of text manually.
#include <stdio.h>
int main(){
char name[30],ch;
int i=0;
printf("Enter name: ");
while(ch!='n') // terminates if user hit enter
{
ch=getchar();
name[i]=ch;
i++;
}
name[i]=' '; // inserting null character at end
printf("Name: %s",name);
return 0;
}
This process to take string is tedious. There are predefined functions gets()
and puts
in C language to read and display string respectively.
More Stories
Notice: Trying to access array offset on value of type bool in /hermes/bosnacweb05/bosnacweb05bi/b2282/ipg.jbbuidtech37209/timecomputers/wp-content/themes/enternews/inc/template-functions.php on line 601
C tutorial in telugu about Strings Part 36
Notice: Trying to access array offset on value of type bool in /hermes/bosnacweb05/bosnacweb05bi/b2282/ipg.jbbuidtech37209/timecomputers/wp-content/themes/enternews/inc/template-functions.php on line 601
C language tutorial in telugu free download Part 35
Notice: Trying to access array offset on value of type bool in /hermes/bosnacweb05/bosnacweb05bi/b2282/ipg.jbbuidtech37209/timecomputers/wp-content/themes/enternews/inc/template-functions.php on line 601
C Language in Telugu Strings exp1