Monday, 25 February 2013

Strings

What is string?

—Array of  characters.
—‘\0’ in string signifies end of the string in memory.
—Strings is enclosed within double quotes.
Initializing Strings
—2 ways
—char month1[]={‘j’,’a’,’n’,’u’,’a’,’r’,’y’};
—char month1[]=“january”;
Example




Array of strings
#include<stdio.h>
const int Num=5;
const int length=9;
main()
{
int j;
char Names[Num][length]={“Tejaswi”,”Prasad”,
                                ”Prashant”,”Anand”, “Priya”};
for(j=0;j<Num;j++) printf(“%s\n”,Names[j]);
}

—Output:
   TejaswiPrasad
    Prasanth
    Anand
Input/output
—gets(string) performs input operation .
—puts(string)  performs output operation.
Example
#include<string.h>
#include<stdio.h>
main()
{  char numstr[20];
    puts("enter the string");
   gets(numstr);
    puts(numstr);
}   
—

No comments:

Post a Comment

String functions

Read This: strncpy() strncat() strstr () strlen() — Predefined function defined in string.h . — — Returns the len...