Programming Articles

Page 1016 of 2547

Print contents of a file in C

Samual Sam
Samual Sam
Updated on 15-Mar-2026 7K+ Views

In C, printing the contents of a file involves opening the file, reading its data character by character or line by line, and displaying it on the console. The fopen(), fgetc(), and fclose() functions are commonly used for this purpose. Syntax FILE *fopen(const char *filename, const char *mode); int fgetc(FILE *stream); int fclose(FILE *stream); Method 1: Reading Character by Character Let's say we have "new.txt" file with the following content − 0, hell!o 1, hello! 2, gfdtrhtrhrt 3, demo Note: Create a file named "new.txt" in your working directory ...

Read More

PHP – Convert a string to a requested character encoding using iconv()

Urmila Samariya
Urmila Samariya
Updated on 15-Mar-2026 1K+ Views

In PHP, the iconv() function is used to convert a string from one character encoding to another. It performs character set conversion on the string from a source encoding to a target encoding, making it essential for handling multilingual text and ensuring proper character display across different systems. Syntax string iconv(string $from_encoding, string $to_encoding, string $string) Parameters The iconv() function accepts three parameters: $from_encoding − The input charset (source encoding) $to_encoding − The output charset (target encoding). You can append //TRANSLIT or //IGNORE for special handling $string − The string to be ...

Read More

EOF, getc() and feof() in C

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 27K+ Views

In C programming, EOF (End of File), getc(), and feof() are essential for file handling operations. EOF is a constant that indicates the end of a file stream, while getc() reads characters from files and feof() checks if the end-of-file indicator has been set. EOF (End of File) EOF stands for End of File and is a macro defined in . The getc() function returns EOF when it reaches the end of file or encounters an error. Syntax #define EOF (-1) Example: Using EOF with getc() Note: This example assumes a ...

Read More

PHP – How to cut out part of a string using iconv_substr()?

Urmila Samariya
Urmila Samariya
Updated on 15-Mar-2026 323 Views

In PHP, the iconv_substr() function is used to cut out a portion of a string based on character position, with proper support for multibyte character encodings like UTF-8. This function is particularly useful when working with international text that may contain special characters. Syntax string iconv_substr(string $string, int $offset, ?int $length = null, ?string $encoding = null) Parameters $string − The original string to extract from $offset − Starting position (0-based). If negative, counts from the end of the string $length − Number of characters to extract. If omitted, extracts to the end ...

Read More

fseek() vs rewind() in C

Samual Sam
Samual Sam
Updated on 15-Mar-2026 3K+ Views

In C, both fseek() and rewind() are used to change the position of the file pointer, but they serve different purposes. fseek() provides flexible positioning anywhere in the file, while rewind() specifically moves the pointer back to the beginning. fseek() Function The fseek() function moves the file pointer to a specific position based on an offset and reference point. Syntax int fseek(FILE *stream, long int offset, int whence) Here are the parameters − stream − Pointer to the FILE object offset − Number of bytes to move from the reference position ...

Read More

PHP – Find the last occurrence of a needle within a haystack using the iconv_strrpos() function

Urmila Samariya
Urmila Samariya
Updated on 15-Mar-2026 316 Views

In PHP, the iconv_strrpos() function is used to find the last occurrence of a needle within a haystack. This function returns the character position of the last match in a string, supporting various character encodings. Syntax iconv_strrpos(string $haystack, string $needle, ?string $encoding = null): int|false Parameters iconv_strrpos() accepts three parameters: $haystack, $needle and $encoding. $haystack − The whole string to search within. $needle − The substring to search for in the haystack. $encoding − The character encoding. If omitted or null, uses iconv.internal_encoding. Return Values iconv_strrpos() returns the numeric ...

Read More

calloc() versus malloc() in C

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 2K+ Views

In C, both malloc() and calloc() are used for dynamic memory allocation, but they have important differences in initialization and usage. Understanding when to use each function is crucial for effective memory management. Syntax void *malloc(size_t size); void *calloc(size_t number, size_t size); malloc() Function The malloc() function allocates a block of memory of the specified size in bytes. It does not initialize the allocated memory, leaving it with garbage values. Parameters size − Size of memory block to allocate in bytes Example #include #include ...

Read More

PHP – How to return the character count of a string using iconv_strlen()?

Urmila Samariya
Urmila Samariya
Updated on 15-Mar-2026 406 Views

In PHP, the iconv_strlen() function is used to return the character count of a given string. This function is particularly useful for multibyte character encodings where regular strlen() might give incorrect results. It was introduced in PHP 5 and the encoding parameter became nullable from PHP 8.0. Syntax int|false iconv_strlen(string $string, ?string $encoding = null) Parameters This function accepts two parameters: $string − The input string to count characters from. $encoding − The character encoding to use. If omitted or null, the value of iconv.internal_encoding configuration option is used. Return ...

Read More

PHP – Set the current setting for character encoding conversion using iconv_set_encoding() function

Urmila Samariya
Urmila Samariya
Updated on 15-Mar-2026 349 Views

In PHP, the iconv_set_encoding() function is used to set the current character encoding conversion. It is an inbuilt function in PHP that changes the value of the internal configuration variable specified by type to encoding. Syntax string iconv_set_encoding(string $type, string $encoding) Parameters iconv_set_encoding() takes two parameters − $type − The $type parameter can be input_encoding, output_encoding or internal_encoding. $encoding − The $encoding parameter is used for the character set. Return Values iconv_set_encoding() returns TRUE on success and FALSE on failure. Example Here's how to set different encoding ...

Read More

PHP – Compose a MIME header field using iconv_mime_encode() function

Urmila Samariya
Urmila Samariya
Updated on 15-Mar-2026 382 Views

In PHP, the iconv_mime_encode() function is used to compose MIME header fields. This built-in function creates properly encoded headers that can contain non-ASCII characters, commonly used in email headers and HTTP responses. Syntax string iconv_mime_encode(string $field_name, string $field_value, array $options=[]) The function returns a string representing a valid MIME header field ? Subject: =?ISO-8859-1?Q?Pr=FCfung_f=FFr?= Entwerfen von einer MIME kopfzeile Note − In the above example, Subject is the field name, and the portion beginning with "=ISO-8859-1?..." is the encoded field value. Parameters The function accepts three parameters − ...

Read More
Showing 10151–10160 of 25,466 articles
Advertisements