Skip to content

Latest commit

 

History

History

0x05-pointers_arrays_strings

0x05. C - Pointers, Arrays, and Strings 👆🔢🔤

This directory contains C programs that demonstrate the use of pointers, arrays, and strings in various functions. Each program focuses on a specific task and provides a solution using C programming concepts.

Programs 📜

0: Reset to 98 ♻️

  • File: 0-reset_to_98.c
  • Description: This function takes a pointer to an integer as a parameter and updates the value it points to, setting it to 98.
  • Prototype: void reset_to_98(int *n)
  • Usage: The function can be called to update an integer to 98.

1: Swap Integers 🔃

  • File: 1-swap.c
  • Description: This function swaps the values of two integers using pointers.
  • Prototype: void swap_int(int *a, int *b)
  • Usage: The function can be called to swap the values of two integers.

2: String Length 📏

  • File: 2-strlen.c
  • Description: This function returns the length of a string (the number of characters in it) excluding the null terminator '\0'.
  • Prototype: int _strlen(char *s)
  • Usage: The function can be called to find the length of a string.

3: Print String 📃

  • File: 3-puts.c
  • Description: This function prints a string followed by a new line to the standard output (stdout).
  • Prototype: void _puts(char *str)
  • Usage: The function can be called to print a string.

4: Print String in Reverse 🔁

  • File: 4-print_rev.c
  • Description: This function prints a string in reverse order followed by a new line.
  • Prototype: void print_rev(char *s)
  • Usage: The function can be called to print a string in reverse.

5: Reverse String 🔁🔃

  • File: 5-rev_string.c
  • Description: This function reverses a string in place.
  • Prototype: void rev_string(char *s)
  • Usage: The function can be called to reverse a string.

6: Print Every Other Character ⏩

  • File: 6-puts2.c
  • Description: This function prints every other character of a string, starting with the first character, followed by a new line.
  • Prototype: void puts2(char *str)
  • Usage: The function can be called to print every other character of a string.

7: Print Second Half of String ➡️

  • File: 7-puts_half.c
  • Description: This function prints the second half of a string, followed by a new line. If the number of characters is odd, it prints the last n characters of the string, where n = (length_of_the_string - 1) / 2.
  • Prototype: void puts_half(char *str)
  • Usage: The function can be called to print the second half of a string.

8: Print Array of Integers 🔢

  • File: 8-print_array.c
  • Description: This function prints n elements of an array of integers, followed by a new line. The numbers are separated by commas and spaces.
  • Prototype: void print_array(int *a, int n)
  • Usage: The function can be called to print elements of an integer array.

9: Copy String 📋

  • File: 9-strcpy.c
  • Description: This function copies the string pointed to by src, including the terminating null byte (\0), to the buffer pointed to by dest.
  • Prototype: char *_strcpy(char *dest, char *src)
  • Return Value: The pointer to dest.
  • Usage: The function can be called to copy a string.

10: Convert String to Integer 🔢🔢

  • File: 100-atoi.c
  • Description: This function converts a string to an integer.
  • Prototype: int _atoi(char *s)
  • Return Value: The converted integer.
  • Usage: The function can be called to convert a string to an integer.

Happy coding! 🚀