replace_tabs - 1Fr3aK2/Cub3d GitHub Wiki

📝 replace_tabs

This function replaces all tab characters ('\t') in a given string with spaces (' ').

⚙️ Parameters

Parameter Type Description
line char* A pointer to the string that will have its tab characters replaced with spaces.

🔁 Returns

Return value Description
char* The modified string with tabs replaced by spaces. If the input string is NULL, it returns NULL.

📖 Description

The replace_tabs function iterates over each character in the given string. If a tab character ('\t') is found, it is replaced with a space (' '). The function modifies the string in-place and returns the modified string.

  • If the input string is NULL, the function returns NULL immediately.
  • The function loops through each character in the string until the null-terminator is reached, replacing each tab character with a space.

💡 Example Usage

char *line = "Hello\tworld!\tThis\tis\ttabbed."; // String with tab characters
replace_tabs(line); // Replaces all '\t' with spaces

printf("Modified line: %s\n", line); // Output: "Hello world! This is tabbed."