has the characters Rafiqul Zaman Khan with 0 appended at the end but is not

Has the characters rafiqul zaman khan with 0 appended

This preview shows page 2 - 4 out of 15 pages.

 has the characters  “Rafiqul Zaman Khan”  with  ‘\0’  appended  at  the end but is not displayed.  Similarly, there is an output function  puts ( )  which prints or displays the value of the string variable. Unlike the  printf,  which stays on the same line after printing  puts  automatically advances the output to the next line after  displaying it. puts (str) ; Example:                          char name [81] = {“Rafiqul Zaman Khan”} ; gets (name) ; /* reads the name */ puts (name) ; /* prints the name */ You can also use the  scanf  function for string input by means of the  %s  format specifier and the  printf  function for  string output. But the  disadvantage  with it is that  scanf  interprets a blank as the end of the particular input   value . As a result you can’t read the above line      Rafiqul Zaman Khan     with  scanf  using a single string  variable. You need to take 3 string variables to read the 3 words as   char first[10], second[10], third[10] ;   scanf (“%s %s %s”, first, second, third) ; printf (“My name is : %s %s %s\n”, first, second, last ) ;   Note that there is no  & (address of ) operator for string variables when they are read with  scanf . Example 1: #include <stdio.h> int main() {    char words[80];    printf("enter a sentence then press enter >");    //scanf("%s",words);   gets(words);    printf("you entered\n");    puts(words);    printf("you entered\n%s",words);    return 0;  }  Page 2 of 15
Image of page 2
Built-in String Functions: Large collections of string processing functions are provided in C through  string.h  file. So, include the  string.h  file  in the programs to use these functions. To use the string functions make sure that the size of the array is sufficient  so  that the strings are terminated with the  ‘\0’  character or the functions will not work properly.   strcat ( string1, string2 ) :   The  strcat  function concatenates  or joins  the  string1  and  string2 . A copy of  string2  is put at the end  of  the  string1 . Make sure that  string1  size is long enough to hold the resulting string (string1 + string2). Example 2:                #include <stdio.h> #include<string.h> int main() {    char   string1[10] = "abc",  string2 [ ] = "def" ;    strcat ( string1, string2) ;     puts ( string1 ) ; /* outputs "abcdef" which is stored in string1 */     return 0;  }   strcpy ( string1, string2 ) :   The  strcpy  function copies  string2  into  string1 . Again make sure that  string1  size is long enough to  hold the resulting string.
Image of page 3
Image of page 4

You've reached the end of your free preview.

Want to read all 15 pages?

  • Spring '10
  • zaman
  • ASCII, Lower case, upper case, Rafiqul Zaman Khan

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes