Friday 23, June 2017
Welcome Guest, Register | Login  
      Home    |    Tutorials    |    Free Ebooks    |    Free Scripts    |    Articles    |    Blog     |    About Us    |    Contact Us

Strings

Character type array is called string. All strings end with the NULL character. Use the %s placeholder in the printf() function to display string values.

 

Declaration:
char name[50];

 

Example

#include 
void main (void )
{
    char *st1 = "abcd";
    char st2[] = "efgh";
    printf( "%s\n", s1);
    printf( "%s\n", s2);

}

 

void main(void){

    char myname[] = { 'S', 't', 'e', 'v', 'e' };

    printf("%s \n",myname);
}

 

String input and output:
The gets function relieves the string from standard input device while put S outputs the string to the standard output device.

The function gets accepts the name of the string as a parameter, and fills the string with characters that are input from the keyboard till newline character is encountered.

The puts function displays the contents stored in its parameter on the standard screen.

The syntax of the gets function is

gets (str_var);

 

The syntax of the puts character is
puts (str_var);

 

Example:

# include < stdio.h >
Void main ( )
{
char myname [40];
printf (“Type your Name :”);
gets (myname);
printf (“Your name is :”);
puts(myname);
}

 

Some String Functions:
Function
Description
strcpy(string1, string2)
Copy string2 into string1
strcat(string1, string2)
Concatenate string2 onto the end of string1
length = strlen(string)
Get the length of a string
strcmp(string1, string2)
Return 0 if string1 equals string2, otherwise nonzero
strchr(string1, chr);

will find the first matching character in a string.

 
     
   
C Language Tutorial
 
  Introduction
Introduction
  First Program
First Program
  Constants and Variables
Constants and Variables
  Loops
Loops
  Control Structure
Control Structure
  Functions
Functions
  Pointers
Pointers
  Arrays
Arrays
  Strings
Strings
  Structures and Unions
Structures and Unions
  File Handling
File Handling
  Graphics
Graphics
 
 
 
Web Designing Tutorials
  HTML Tutorial
HTML Tutorial
  DHTML Tutorial
DHTML  Tutorial
  CSS Tutorial
CSS Tutorial
  XHTML Tutorial
XHTML Tutorial
 
Programming Languages Tutorials
  C Language Tutorial
C Language Tutorial
  C++ Tutorial
C++ Tutorial
  Java Language Tutorial
Java Language Tutorial
  Data Structure Theory Tutorial
Data Structure Theory Tutorial
 
Server Side Scripting Tutorials
  PHP Tutorial
PHP Tutorial
  SQL Tutorial
SQL Tutorial
  ASP Tutorial
ASP Tutorial
 
Client Side Scripting Tutorials
  JavaScript Tutorial
JavaScript Tutorial
  VBScript Tutorial
VBScript Tutorial
 
 
 
POPULAR E-BOOKS
 
Download BMA s Marketing Articles Vol I Ebook BMA s Marketing Articles Vol I
   
Download Back to Basics Making the Most of Affiliate Marketing  Ebook Back to Basics Making the Most of Affiliate Marketing
   
Download Essentials of the Java Programming Language: A Hands-On Guide  Ebook Essentials of the Java Programming Language: A Hands-On Guide
   
Download Introduction to Programming (in Java) - An Interdisciplinary Approach  Ebook Introduction to Programming (in Java) - An Interdisciplinary Approach
   
Download Domain Name Whitepaper  Making Money with Domains  Ebook Domain Name Whitepaper Making Money with Domains
   
     
Studiesinn.com 2017 All Rights Reserved.
 
Website Designed & Developed by TechXprtz