fredsiika/30-seconds-of-c

Repository files navigation

30-Seconds-of-C-Logo

PRs WelcomeAwesomeLicense


🔌Your plug to a curated collection of useful C Programming tutorials, snippets, and projects that you can understand in 30 seconds or less.



P.S: This repository is a work in progress

  • Use Ctrl + F or command + F to search for a snippet.
  • Contributions welcome, please read the contribution guide.

Motivation for this project The core goal of 30 seconds of C is to provide a public record of my journey to learn c programming. It's my goal to provide a quality resource for both beginners and advanced c progammers/developers. My initial motivation for creating this repository was to use it as a tool to document my journey at the 42 Silicon Valley - an engineering and programming. The contents of this repo are designed to help you write real time C programs on your own.

View contents

Integer

Character

  • char

Floating Point

  • float
  • Double
View contentsView contentsView contents

Purpose: This repo provides useful tips to understand how to achieve 100% at 42 Silicon Valley exams. A great developer like you 😎, however, should not just memorize the answers.


Create a program that takes a string, and displays the first 'a' character it encounters in it, followed by a newline. If there are no 'a' characters in the string, the program just writes a newline. If the number of parameters is not 1, the program displays 'a' followed by a newline.

$> ./aff_a "abc" | cat -e
a$
$> ./aff_a "dubO a POIL" | cat -e
a$
$> ./aff_a "zz sent le poney" | cat -e
$
$> ./aff_a | cat -e
a$
Answer
#include <unistd.h>

int	main(int argc, char **argv)
{
	if (argc != 2)
		write(1, "a", 1);
	else
	{
		while (*argv[1])
			if (*argv[1] == 'a')
			{
				write(1, "a", 1);
				argv[1]++;
				break;
			}
	}
	write(1, "\n", 1);
	return (0);
}


⬆ Back to top

Write a program that displays all digits in descending order, followed by a newline.

$> ./ft_countdown | cat -e
9876543210$
$>
Answer
#include <unistd.h>

int	main(void)
{
	char c;
	c = '9';
	while (c >= '0')
	{
		write(1, &c, 1);
		c--;
	}
	write(1, "\n", 1);
	return (0);
}


⬆ Back to top

Write a function that displays all digits in ascending order.

Your function must be declared as follows:

void ft_print_numbers(void);

Answer
#include <unistd.h>

int	main(void)
{
	char c;

	c = '0';
	while (c <= '9')
	{
		write(1, &c,1);
		c++;
	}
	write(1, "\n", 1);
	return (0);
}


⬆ Back to top

If you are new to C Programming, try taking a look at some of these references.



The idea behind 30 Seconds of C was inspired some people who created similar collections in other programming languages and environments. Here are the ones we like the most:

Do you have a cool idea for a new snippet, or want to add your own tips? Checkout contributing.md.


Fred Siika

Grace Nelore

Icon made by Smashicons from www.flaticon.com is licensed by CC 3.0 BY.
This site was built using Pages.


⬆ Back to top

About

🔌Curated collection of useful C Programming tutorials, snippets, and projects that you can understand in 30 seconds or less.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •