- 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[ ] ="cprogramming";
The most common string function are:
- fputs( )
- fgets( )
- strcpy( )
- 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(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.