C Programming - Library Functions
- Library Functions - General Questions
- Library Functions - Find Output of Program
- Library Functions - Point Out Errors
- Library Functions - True / False Questions
- Library Functions - Yes / No Questions
C string is a character sequence stored as a one-dimensional character array and terminated with a null character('\0', called NULL in ASCII).
The length of a C string is found by searching for the (first) NULL byte.
FILE - a structure containing the information about a file or text stream needed to perform input or output operations on it, including:
=> a file descriptor, the current stream position,
=> an end-of-file indicator,
=> an error indicator,
=> a pointer to the stream's buffer, if applicable
fpos_t - a non-array type capable of uniquely identifying the position of every byte in a file.
size_t - an unsigned integer type which is the type of the result of the sizeof operator.
The ftell() function shall obtain the current value of the file-position indicator for the stream pointed to by stream.
Example:
#include <stdio.h>
int main(void)
{
FILE *stream;
stream = fopen("MYFILE.TXT", "w+");
fprintf(stream, "This is a test");
printf("The file pointer is at byte %ld\n", ftell(stream));
fclose(stream);
return 0;
}
fwrite() - Unformatted write in to a file.
fscanf() - Formatted read from a file.
g = strcmp(s1, s2); returns 0 when the strings are equal, a negative integer when s1 is less than s2, or a positive integer if s1 is greater than s2, that strcmp() not only returns -1, 0 and +1, but also other negative or positive values(returns difference between the first non-matching pair of characters between s1 and s2).
A possible implementation for strcmp() in "The Standard C Library".
int strcmp (const char * s1, const char * s2)
{
for(; *s1 == *s2; ++s1, ++s2)
{
if(*s1 == 0)
return 0;
}
return *(unsigned char *)s1 < *(unsigned char *)s2 ? -1 : 1;
}