Giter VIP home page Giter VIP logo

printf's Introduction

Printf.

int printf ( const char * format, ... );

This is the first group project that we have at Alx Software Engineering Program, which consists of replicating the printf (3) function of language c, calling it this way _printf.

This function is part of the standard library and to use it we must specify the header file <stdio.h>.

Writes the C string pointed by format to the standard output (stdout). If format includes format specifiers (subsequences beginning with %), the additional arguments following format are formatted and inserted in the resulting string replacing their respective specifiers.

Parameters

format -> C string that contains the text to be written to stdout.

Where the specifier character at the end is the most significant component, since it defines the type and the interpretation of its corresponding argument:

Specifier Output Example
c Character A
s String of characters
% A % followed by another % character will write a single % to the stream %
i and d Signed decimal integer 98
b Unsigned binary 10101
u Unsigned decimal integer 98
o Unsigned octal 5523
x Unsigned hexadecimal integer (lowercase) 36264eb
X Unsigned hexadecimal integer (uppercase) 36264EB
r Reversed string gnirts
R Rot13 string cevags
Return Value.

On success, the total number of characters written is returned. If a writing error occurs, the error indicator (ferror) is set and a negative number is returned.

The tasks.

-[x] I'm not going anywhere. You can print that wherever you want to. I'm here and I'm a Spur for life. Write a function that produces output according to a format.

  • Prototype:int _printf(const char *format, ...);
  • Returns: the number of characters printed (excluding the null byte used to end output to strings)
  • write output to stdout, the standard output stream
  • format is a character string. The format string is composed of zero or more directives. See man 3 printf for more detail. You need to handle the following conversion specifiers: -- c -- s -- %

-[x] Education is when you read the fine print. Experience is what you get if you don't Handle the following conversion specifiers: -- d --i

Functions we use.

int _putchar(char c); /*writes the character c to stdout */
int _printf(const char *format, ...);/* function that produces output according to a format.*/
int print_char(va_list c);/*writes the character c to stdout */
int print_string(va_list s);/*writes the character c to stdout */
int print_int(va_list i);/*function that prints an integer */
int print_dec(va_list d);/* function that prints an decimal*/

How to use.

Complilation

All of the .c files along with a main.c file are to be compiled with gcc 4.8.4 on Ubuntu 14.04 LTS with the flags -Wall Werror -Westra and -pedantic.

The files will be compiled this way:

  • gcc -Wall -Werror -Wextra -pedantic *.c

Use.

In the main.c file, use the _printf function like so:

#include "main.h"
/**
 * main - main function of program
 * Return: always 0
 */
int main(void)
{
	int num;
	char *string;
	
	num = 98;
	string = "Hello, BEST School!"
	_printf("%s is %i.\n", string, num);
	return (0);
}
linux>$  gcc -Wall -Werror -Wextra -pedantic *.c -o print_program
linux>$  ./print_program
Hello, BEST School is 98.
linux>$

Contributor

printf's People

Contributors

codewithsegnet avatar florence93 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.