Advertisement
Guest User

Revision exam day 5

a guest
Jul 27th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.98 KB | None | 0 0
  1. /* ************************************************************************** */
  2. /* */
  3. /* ::: :::::::: */
  4. /* ft_putstr.c :+: :+: :+: */
  5. /* +:+ +:+ +:+ */
  6. /* By: sboucher <marvin@42.fr> +#+ +:+ +#+ */
  7. /* +#+#+#+#+#+ +#+ */
  8. /* Created: 2017/07/18 17:44:59 by sboucher #+# #+# */
  9. /* Updated: 2017/07/18 17:45:40 by sboucher ### ########.fr */
  10. /* */
  11. /* ************************************************************************** */
  12.  
  13. void ft_putchar(char c);
  14.  
  15. void ft_putstr(char *str)
  16. {
  17. int i;
  18.  
  19. i = 0;
  20. while (str[i] != '\0')
  21. {
  22. ft_putchar(str[i]);
  23. i++;
  24. }
  25. }
  26. /* ************************************************************************** */
  27. /* */
  28. /* ::: :::::::: */
  29. /* ft_putnbr.c :+: :+: :+: */
  30. /* +:+ +:+ +:+ */
  31. /* By: sboucher <marvin@42.fr> +#+ +:+ +#+ */
  32. /* +#+#+#+#+#+ +#+ */
  33. /* Created: 2017/07/12 11:57:02 by sboucher #+# #+# */
  34. /* Updated: 2017/07/12 19:52:09 by sboucher ### ########.fr */
  35. /* */
  36. /* ************************************************************************** */
  37.  
  38. void ft_putchar(char c);
  39.  
  40. void ft_putnbr(int nb)
  41. {
  42. unsigned int n;
  43.  
  44. n = nb;
  45. if (nb < 0)
  46. {
  47. n = n * -1;
  48. ft_putchar('-');
  49. }
  50. if (n / 10 > 0)
  51. {
  52. ft_putnbr(n / 10);
  53. }
  54. ft_putchar(n % 10 + '0');
  55. }
  56. /* ************************************************************************** */
  57. /* */
  58. /* ::: :::::::: */
  59. /* ft_atoi.c :+: :+: :+: */
  60. /* +:+ +:+ +:+ */
  61. /* By: sboucher <marvin@42.fr> +#+ +:+ +#+ */
  62. /* +#+#+#+#+#+ +#+ */
  63. /* Created: 2017/07/09 12:56:41 by sboucher #+# #+# */
  64. /* Updated: 2017/07/12 23:16:32 by sboucher ### ########.fr */
  65. /* */
  66. /* ************************************************************************** */
  67.  
  68. int ft_atoi(char *str)
  69. {
  70. int i;
  71. int ent;
  72. int neg;
  73.  
  74. neg = 1;
  75. ent = 0;
  76. i = 0;
  77. while ((str[i] >= 9 && str[i] <= 13) || str[i] == 32)
  78. i++;
  79. if (str[i] == '-' || str[i] == '+')
  80. {
  81. if (str[i] == '-')
  82. neg = -1;
  83. i++;
  84. }
  85. while (str[i] >= '0' && str[i] <= '9')
  86. {
  87. ent = ent * 10 + str[i] - 48;
  88. i++;
  89. }
  90. return (ent * neg);
  91. }
  92. /* ************************************************************************** */
  93. /* */
  94. /* ::: :::::::: */
  95. /* ft_strcpy.c :+: :+: :+: */
  96. /* +:+ +:+ +:+ */
  97. /* By: sboucher <marvin@42.fr> +#+ +:+ +#+ */
  98. /* +#+#+#+#+#+ +#+ */
  99. /* Created: 2017/07/12 23:20:34 by sboucher #+# #+# */
  100. /* Updated: 2017/07/18 17:46:28 by sboucher ### ########.fr */
  101. /* */
  102. /* ************************************************************************** */
  103.  
  104. char *ft_strcpy(char *dest, char *src)
  105. {
  106. int i;
  107.  
  108. i = 0;
  109. while (src[i] != '\0')
  110. {
  111. dest[i] = src[i];
  112. i++;
  113. }
  114. dest[i] = src[i];
  115. return (dest);
  116. }
  117. /* ************************************************************************** */
  118. /* */
  119. /* ::: :::::::: */
  120. /* ft_strncpy.c :+: :+: :+: */
  121. /* +:+ +:+ +:+ */
  122. /* By: sboucher <marvin@42.fr> +#+ +:+ +#+ */
  123. /* +#+#+#+#+#+ +#+ */
  124. /* Created: 2017/07/13 10:30:53 by sboucher #+# #+# */
  125. /* Updated: 2017/07/13 14:20:40 by sboucher ### ########.fr */
  126. /* */
  127. /* ************************************************************************** */
  128.  
  129. char *ft_strncpy(char *dest, char *src, unsigned int n)
  130. {
  131. unsigned int i;
  132.  
  133. i = 0;
  134. while (src[i] != '\0' && n > i)
  135. {
  136. dest[i] = src[i];
  137. i++;
  138. }
  139. while (n > i)
  140. {
  141. dest[i] = '\0';
  142. i++;
  143. }
  144. return (dest);
  145. }
  146. /* ************************************************************************** */
  147. /* */
  148. /* ::: :::::::: */
  149. /* ft_strstr.c :+: :+: :+: */
  150. /* +:+ +:+ +:+ */
  151. /* By: sboucher <marvin@42.fr> +#+ +:+ +#+ */
  152. /* +#+#+#+#+#+ +#+ */
  153. /* Created: 2017/07/13 17:31:50 by sboucher #+# #+# */
  154. /* Updated: 2017/07/17 02:00:11 by sboucher ### ########.fr */
  155. /* */
  156. /* ************************************************************************** */
  157.  
  158. char *ft_strstr(char *str, char *to_find)
  159. {
  160. int taille_str;
  161. int taille_to;
  162. int m;
  163.  
  164. taille_str = 0;
  165. taille_to = 0;
  166. while (str[taille_str] != '\0')
  167. {
  168. m = taille_str;
  169. while (to_find[taille_to] != '\0' && str[m] == to_find[taille_to])
  170. {
  171. if (to_find[taille_to + 1] == '\0')
  172. return (&str[taille_str]);
  173. taille_to++;
  174. m++;
  175. }
  176. taille_to = 0;
  177. taille_str++;
  178. }
  179. return (0);
  180. }
  181. /* ************************************************************************** */
  182. /* */
  183. /* ::: :::::::: */
  184. /* ft_strcmp.c :+: :+: :+: */
  185. /* +:+ +:+ +:+ */
  186. /* By: sboucher <marvin@42.fr> +#+ +:+ +#+ */
  187. /* +#+#+#+#+#+ +#+ */
  188. /* Created: 2017/07/17 11:09:24 by sboucher #+# #+# */
  189. /* Updated: 2017/07/17 14:36:15 by sboucher ### ########.fr */
  190. /* */
  191. /* ************************************************************************** */
  192.  
  193. int ft_strcmp(char *s1, char *s2)
  194. {
  195. int i;
  196.  
  197. i = 0;
  198. while (s1[i] || s2[i])
  199. {
  200. if (s1[i] == s2[i])
  201. i++;
  202. if (s1[i] != s2[i])
  203. {
  204. if (s1[i] < s2[i])
  205. return (s1[i] - s2[i]);
  206. if (s1[i] > s2[i])
  207. return (s1[i] - s2[i]);
  208. }
  209. }
  210. return (0);
  211. }
  212. /* ************************************************************************** */
  213. /* */
  214. /* ::: :::::::: */
  215. /* ft_strncmp.c :+: :+: :+: */
  216. /* +:+ +:+ +:+ */
  217. /* By: sboucher <marvin@42.fr> +#+ +:+ +#+ */
  218. /* +#+#+#+#+#+ +#+ */
  219. /* Created: 2017/07/17 13:38:39 by sboucher #+# #+# */
  220. /* Updated: 2017/07/18 20:10:20 by sboucher ### ########.fr */
  221. /* */
  222. /* ************************************************************************** */
  223.  
  224. int ft_strncmp(char *s1, char *s2, unsigned int n)
  225. {
  226. unsigned int i;
  227.  
  228. i = 0;
  229. while (s1[i] != '\0' && s2[i] != '\0' && s1[i] == s2[i] && n > i)
  230. i++;
  231. return (s1[i] - s2[i]);
  232. }
  233. /* ************************************************************************** */
  234. /* */
  235. /* ::: :::::::: */
  236. /* ft_strupcase.c :+: :+: :+: */
  237. /* +:+ +:+ +:+ */
  238. /* By: sboucher <marvin@42.fr> +#+ +:+ +#+ */
  239. /* +#+#+#+#+#+ +#+ */
  240. /* Created: 2017/07/17 14:42:37 by sboucher #+# #+# */
  241. /* Updated: 2017/07/17 15:35:40 by sboucher ### ########.fr */
  242. /* */
  243. /* ************************************************************************** */
  244.  
  245. char *ft_strupcase(char *str)
  246. {
  247. int i;
  248.  
  249. i = 0;
  250. while (str[i] != '\0')
  251. {
  252. if (str[i] >= 'a' && str[i] <= 'z')
  253. str[i] = str[i] + ('A' - 'a');
  254. i++;
  255. }
  256. return (str);
  257. }
  258. /* ************************************************************************** */
  259. /* */
  260. /* ::: :::::::: */
  261. /* ft_strlowcase.c :+: :+: :+: */
  262. /* +:+ +:+ +:+ */
  263. /* By: sboucher <marvin@42.fr> +#+ +:+ +#+ */
  264. /* +#+#+#+#+#+ +#+ */
  265. /* Created: 2017/07/17 15:38:46 by sboucher #+# #+# */
  266. /* Updated: 2017/07/17 15:50:37 by sboucher ### ########.fr */
  267. /* */
  268. /* ************************************************************************** */
  269.  
  270. char *ft_strlowcase(char *str)
  271. {
  272. int i;
  273.  
  274. i = 0;
  275. while (str[i] != '\0')
  276. {
  277. if (str[i] >= 'A' && str[i] <= 'Z')
  278. str[i] = str[i] - ('A' - 'a');
  279. i++;
  280. }
  281. return (str);
  282. }
  283. /* ************************************************************************** */
  284. /* */
  285. /* ::: :::::::: */
  286. /* ft_strcapitalize.c :+: :+: :+: */
  287. /* +:+ +:+ +:+ */
  288. /* By: sboucher <marvin@42.fr> +#+ +:+ +#+ */
  289. /* +#+#+#+#+#+ +#+ */
  290. /* Created: 2017/07/17 17:29:12 by sboucher #+# #+# */
  291. /* Updated: 2017/07/17 21:47:31 by sboucher ### ########.fr */
  292. /* */
  293. /* ************************************************************************** */
  294.  
  295. char *ft_strcapitalize(char *str)
  296. {
  297. int i;
  298.  
  299. i = 0;
  300. if (str[i] >= 'a' && str[i] <= 'z')
  301. str[i] = str[i] + ('A' - 'a');
  302. while (str[i] != '\0')
  303. {
  304. if ((str[i] >= 'A' && str[i] <= 'Z') ||
  305. (str[i] >= 'a' && str[i] <= 'z') ||
  306. (str[i] >= '0' && str[i] <= '9'))
  307. {
  308. if (str[i + 1] >= 'A' && str[i + 1] <= 'Z')
  309. str[i + 1] = str[i + 1] + 32;
  310. }
  311. else
  312. {
  313. if (str[i + 1] >= 'a' && str[i + 1] <= 'z')
  314. str[i + 1] = str[i + 1] - 32;
  315. }
  316. i++;
  317. }
  318. return (str);
  319. }
  320. /* ************************************************************************** */
  321. /* */
  322. /* ::: :::::::: */
  323. /* ft_str_is_alpha.c :+: :+: :+: */
  324. /* +:+ +:+ +:+ */
  325. /* By: sboucher <marvin@42.fr> +#+ +:+ +#+ */
  326. /* +#+#+#+#+#+ +#+ */
  327. /* Created: 2017/07/17 23:10:12 by sboucher #+# #+# */
  328. /* Updated: 2017/07/17 23:44:30 by sboucher ### ########.fr */
  329. /* */
  330. /* ************************************************************************** */
  331.  
  332. int ft_str_is_alpha(char *str)
  333. {
  334. int i;
  335.  
  336. i = 0;
  337. while (str[i] != '\0')
  338. {
  339. if (str[i] < 'A' || str[i] > 'z')
  340. return (0);
  341. i++;
  342. }
  343. return (1);
  344. }
  345. /* ************************************************************************** */
  346. /* */
  347. /* ::: :::::::: */
  348. /* ft_str_is_numeric.c :+: :+: :+: */
  349. /* +:+ +:+ +:+ */
  350. /* By: sboucher <marvin@42.fr> +#+ +:+ +#+ */
  351. /* +#+#+#+#+#+ +#+ */
  352. /* Created: 2017/07/17 23:51:37 by sboucher #+# #+# */
  353. /* Updated: 2017/07/18 00:07:17 by sboucher ### ########.fr */
  354. /* */
  355. /* ************************************************************************** */
  356.  
  357. int ft_str_is_numeric(char *str)
  358. {
  359. int i;
  360.  
  361. i = 0;
  362. while (str[i] != '\0')
  363. {
  364. if (str[i] < '0' || str[i] > '9')
  365. return (0);
  366. i++;
  367. }
  368. return (1);
  369. }
  370. /* ************************************************************************** */
  371. /* */
  372. /* ::: :::::::: */
  373. /* ft_str_is_lowercase.c :+: :+: :+: */
  374. /* +:+ +:+ +:+ */
  375. /* By: sboucher <marvin@42.fr> +#+ +:+ +#+ */
  376. /* +#+#+#+#+#+ +#+ */
  377. /* Created: 2017/07/17 23:56:09 by sboucher #+# #+# */
  378. /* Updated: 2017/07/18 18:10:55 by sboucher ### ########.fr */
  379. /* */
  380. /* ************************************************************************** */
  381.  
  382. int ft_str_is_lowercase(char *str)
  383. {
  384. int i;
  385.  
  386. i = 0;
  387. while (str[i] != '\0')
  388. {
  389. if (str[i] < 'a' || str[i] > 'z')
  390. return (0);
  391. i++;
  392. }
  393. return (1);
  394. }
  395. /* ************************************************************************** */
  396. /* */
  397. /* ::: :::::::: */
  398. /* ft_str_is_uppercase.c :+: :+: :+: */
  399. /* +:+ +:+ +:+ */
  400. /* By: sboucher <marvin@42.fr> +#+ +:+ +#+ */
  401. /* +#+#+#+#+#+ +#+ */
  402. /* Created: 2017/07/18 00:22:27 by sboucher #+# #+# */
  403. /* Updated: 2017/07/18 00:22:37 by sboucher ### ########.fr */
  404. /* */
  405. /* ************************************************************************** */
  406.  
  407. int ft_str_is_uppercase(char *str)
  408. {
  409. int i;
  410.  
  411. i = 0;
  412. while (str[i] != '\0')
  413. {
  414. if (str[i] < 'A' || str[i] > 'Z')
  415. return (0);
  416. i++;
  417. }
  418. return (1);
  419. }
  420. /* ************************************************************************** */
  421. /* */
  422. /* ::: :::::::: */
  423. /* ft_str_is_printable.c :+: :+: :+: */
  424. /* +:+ +:+ +:+ */
  425. /* By: sboucher <marvin@42.fr> +#+ +:+ +#+ */
  426. /* +#+#+#+#+#+ +#+ */
  427. /* Created: 2017/07/18 00:24:19 by sboucher #+# #+# */
  428. /* Updated: 2017/07/18 00:46:05 by sboucher ### ########.fr */
  429. /* */
  430. /* ************************************************************************** */
  431.  
  432. int ft_str_is_printable(char *str)
  433. {
  434. int i;
  435.  
  436. i = 0;
  437. while (str[i] != '\0')
  438. {
  439. if (str[i] < ' ' || str[i] > '~')
  440. return (0);
  441. i++;
  442. }
  443. return (1);
  444. }
  445. /* ************************************************************************** */
  446. /* */
  447. /* ::: :::::::: */
  448. /* ft_strcat.c :+: :+: :+: */
  449. /* +:+ +:+ +:+ */
  450. /* By: sboucher <marvin@42.fr> +#+ +:+ +#+ */
  451. /* +#+#+#+#+#+ +#+ */
  452. /* Created: 2017/07/18 00:57:12 by sboucher #+# #+# */
  453. /* Updated: 2017/07/18 01:34:42 by sboucher ### ########.fr */
  454. /* */
  455. /* ************************************************************************** */
  456.  
  457. char *ft_strcat(char *dest, char *src)
  458. {
  459. int i;
  460. int k;
  461.  
  462. i = 0;
  463. k = 0;
  464. while (dest[i] != '\0')
  465. i++;
  466. while (src[k])
  467. {
  468. dest[i + k] = src[k];
  469. k++;
  470. }
  471. dest[i + k] = '\0';
  472. return (dest);
  473. }
  474. /* ************************************************************************** */
  475. /* */
  476. /* ::: :::::::: */
  477. /* ft_strncat.c :+: :+: :+: */
  478. /* +:+ +:+ +:+ */
  479. /* By: sboucher <marvin@42.fr> +#+ +:+ +#+ */
  480. /* +#+#+#+#+#+ +#+ */
  481. /* Created: 2017/07/18 01:45:04 by sboucher #+# #+# */
  482. /* Updated: 2017/07/18 02:09:27 by sboucher ### ########.fr */
  483. /* */
  484. /* ************************************************************************** */
  485.  
  486. char *ft_strncat(char *dest, char *src, int nb)
  487. {
  488. int i;
  489. int k;
  490.  
  491. i = 0;
  492. k = 0;
  493. while (dest[i] != '\0')
  494. i++;
  495. while (src[k] && nb > k)
  496. {
  497. dest[i + k] = src[k];
  498. k++;
  499. }
  500. dest[i + k] = '\0';
  501. return (dest);
  502. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement