-->





Translate

How strings are stored and retrieved in C language

1 comment
String Handling in C programming with common functions
  • String is a combination of characters and it is enclosed in double quotes
  • Character array is used to hold string.
  • Char name_ of_string[ string _ length];
  • Char is data type and string length is the name of characters in a string.
  • A string variable can also be declared without specifying the number of characters.
  • The variables that is used to store a string is called string variables.
  • The last character of a string must be a Null character \0 i.e. Null character \0 is added the end of the string.
  • Null character \0 is also included in the string length.

The string can be initialized
char languageName[20]="cprogramming";
char languageName[ ]   ="cprogramming";

The most common string function are:
  • fputs( )
  • fgets( )
  • strcpy( )
What is fputs() function? Explain with the help of an example.
  • It is used to write a string of characters in to a file
  • The function writes the string until the null character \0 is reached
  • It does not add the null character of the file
  • The file must be opened or in append mode to write this funcation

fputs() Example
Syntax:
fputs(string, file_pointer);

FILE*fp;

Fp = fopen(“test1.txt”,”w”);

fputs(“The string of your choice:”,fp);

The above string is written in test 1.txt file.


What is fgets() funcation? Explain with the help of an example.

  • It is used to read a string of characters of a certain length from a file.
  • The file must be opened or in append mode to write this function.


fgets(string or string variable, n, file _pointer)
N is the number of characters read from the file.

1 comment:

  1. Actually,C++ programming consider most favorite platform for programmers to do innovation. This article completely covers how to use string in C++ programming. This all shows in this article with quoted example.

    ReplyDelete