The ENTER key n character will not be part of the string Also the easiest way

The enter key n character will not be part of the

This preview shows page 1 - 3 out of 4 pages.

including blanks up to pressing the "ENTER" key. The "ENTER" key (' \n ') character will not be part of the string. Also the easiest way to output string is by using the puts function as in: puts(name); puts(name) is equivalent to printf("%s\n",name) For scanning from file, we have fgets(str, n, file) which expects 3 arguments: string variable, number of characters to scan and the file to scan from. If end of line ('\n') is 1
Image of page 1
encountered before scanning n-1 characters, fgets will stop reading otherwise it reads n-1 characters. Also we can print into a file using fputs(str, file). You can also use the scanf/printf functions for string I/O using the %s format specifier. However, scanf terminates reading on encountering the blank character, so first and last names must be read separately: char first[10],last[10],full[20]; printf("\nEnter your first name: "); scanf("%s",first); printf("\nEnter your last name: "); scanf("%s",last); printf("\nYour full name is : %s %s",first,last); Note that the address of operator, & , is not used in the scanf function. gets, puts, fgets, and fputs can be accessed through the header file, stdio.h . Built-in string functions: Built-in string processing functions can be accessed through the header file, string.h . Some of these are: strcat(string1, string2) à appends strings2 to string1 strcpy(string1, string2) à replaces string1 with string2 strlen(string1) à returns the length of string1 excluding NULL character strchr(str, ch) à
Image of page 2
Image of page 3

You've reached the end of your free preview.

Want to read all 4 pages?

  • Summer '14
  • Darwish

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture