본문 바로가기

C언어 in 42Seoul (라피신)

c04

-R CheckForbiddenSourceHeader

-Wall -Wextra -Werror

putStr

putStrLn과 유사한 함수로 문자열을 받아서 I/O 작업을 리턴합니다. putStrLn 함수와의 차이점은 문자열을 출력하고 개행을 넣지않는다는 점 입니다.

main = do putStr "Hey, " putStr "I'm " putStrLn "Andy!" $ runhaskell putstr_test.hs Hey, I'm Andy!

함수의 타입은 putStr :: String -> IO ()입니다. 따라서 함수 수행 결과는 아무것도 하지않는 I/O 작업에 캡슐화됩니다.

 

#include <stdio.h>
#include <unistd.h>
#include <string.h>
void	ft_putstr(char *str)
{
	int i;

	i = 0;
	while (str[i])
	{
		write(1, &str[i], 1);
		i++;
	}
}
int		main(void)
{
	char a[] = "asdf";
	ft_putstr(a);
	return (0);
}
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   ft_putnbr.c                                        :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: minjeoki <minjeoki@student.42seoul.kr>     +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2021/02/26 00:32:12 by minjeoki          #+#    #+#             */
/*   Updated: 2021/02/26 00:48:26 by minjeoki         ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include <unistd.h>
#include <stdio.h>
void ft_write(char c)
{
	write(1, &c, 1);
}

void	ft_putnbr(int nb)
{

	if (nb > 9)
	{
		ft_putnbr(nb / 10);
		nb = nb % 10 ;
	}
	if (0<=nb && nb <=9)
		ft_write(nb + '0');
	if (nb<0 && nb != -2147483648)
	{
		nb = -nb;
		write(1, "-", 1);
		ft_putnbr(nb);
	}
	if (nb == -2147483648)
	{
		write(1, "-", 1);
		write(1, "2147483648", 10);
	}

}

int		main(void)
{
	ft_putnbr(-2147483648);
	return (0);
}

'C언어 in 42Seoul (라피신)' 카테고리의 다른 글

exam01대비  (0) 2021.02.26
c04  (0) 2021.02.26
c00  (0) 2021.02.21
c00  (0) 2021.02.20
시험 대비 c 00  (0) 2021.02.19