GithubHelp home page GithubHelp logo

abranhe / cs50 Goto Github PK

View Code? Open in Web Editor NEW
5.0 1.0 0.0 17 KB

The CS50 Library for C ready to use with Clib

Home Page: https://cs50.readthedocs.io/library/c/

License: Other

Makefile 2.44% C 97.56%
clibs clib cs50 c-library c

cs50's Introduction





cs50: The CS50 Library for C ready to use with Clib



Description

I was a CS50 student once, working with strings was easier back then while coding in C. So why not keep using it on future projects?

Well, I created this project to integrate it Clib and to be easy to use as a dependency for future projects.

Keep in mind

If you are a CS50 student don't take this project as example to follow the style, make sure you read instead the style guide for the C Programming Language from CS50.

Installation

Installing using Clib

$ clib install abranhe/cs50

For more installation options see the official library from the CS50 team.

Usage

$ ./example
abranhe
hello, abranhe
example.c
#include <stdio.h>
#include "cs50.h"

int main()
{
	string s = get_string();
	printf("hello, %s\n", s);
	return 0;
}

API

string

Type representing a C string. Aliased to char *.

void eprintf(const char *format, ...)

Prints an error message formatted like printf() to standard error, prefixing it with file and line number from which the function was called.

Params:
  • format - the printf()-like format string used to display the prompt
  • ... – values to be substituted into the format string a la printf()

char get_char(const char *format, ...)

Prompts user for a line of text from standard input and returns the equivalent char; if text does not represent a single char, user is reprompted.

Params:
  • format - the printf()-like format string used to display the prompt
  • ... – values to be substituted into the format string a la printf()
Returns:
  • the char equivalent to the line read from stdin, or CHAR_MAX on error

double get_double(const char *format, ...)

Prompts user for a line of text from standard input and returns the equivalent double; if text does not represent a double or would cause overflow or underflow, user is reprompted.

Params:
  • format - the printf()-like format string used to display the prompt
  • ... – values to be substituted into the format string a la printf()
Returns:
  • the double equivalent to the line read from stdin in [DBL_MIN, DBL_MAX), as precisely as possible, or DBL_MAX on error

int get_int(const char *format, ...)

Prompts user for a line of text from standard input and returns the equivalent int; if text does not represent an int or would cause overflow, user is reprompted.

Params:
  • format - the printf()-like format string used to display the prompt
  • ... – values to be substituted into the format string a la printf()
Returns:
  • the int equivalent to the line read from stdin in [INT_MIN, INT_MAX) or INT_MAX on error

float get_float(const char *format, ...)

Prompts user for a line of text from standard input and returns the equivalent float; if text does not represent a float or would cause overflow or underflow, user is reprompted.

Params:
  • format - the printf()-like format string used to display the prompt
  • ... – values to be substituted into the format string a la printf()
Returns:
  • the float equivalent to the line read from stdin in [FLT_MIN, FLT_MAX), as precisely as possible, or FLT_MAX on error

long get_long(const char *format, ...)

Prompts user for a line of text from standard input and returns the equivalent float; if text does not represent a long or would cause overflow or underflow, user is reprompted.

Params:
  • format - the printf()-like format string used to display the prompt
  • ... – values to be substituted into the format string a la printf()
Returns:
  • the float equivalent to the line read from stdin in [LONG_MIN, LONG_MAX), as precisely as possible, or LONG_MAX on error

char *get_string(const char *format, ...)

*Prompts user for a line of text from standard input and returns it as a string (char ), sans trailing line ending. Supports CR (\r), LF (\n), and CRLF (\r\n) as line endings. Stores string on heap, but library’s destructor frees memory on program’s exit.

Params:
  • format - the printf()-like format string used to display the prompt
  • ... – values to be substituted into the format string a la printf()
Returns:
  • the read line as a string sans line endings, or NULL on EOF.

For more information read the documentation at cs50.readthedocs.io/library/c

Related

  • cs50: Official CS50 Library for C

License

The CS50 library is owned and managed by the Team behind CS50, learn more.

cs50's People

Contributors

abranhe avatar

Stargazers

 avatar  avatar  avatar  avatar  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.