File tree Expand file tree Collapse file tree 4 files changed +47
-2
lines changed
Expand file tree Collapse file tree 4 files changed +47
-2
lines changed Original file line number Diff line number Diff line change @@ -77,6 +77,9 @@ int p_func(va_list ap, char specifier)
7777 case '%' :
7878 char_count += write (1 , "%" , 1 );
7979 break ;
80+ case 'R' :
81+ char_count += rot13 (ap );
82+ break ;
8083 }
8184 va_end (ap );
8285 return (char_count );
Original file line number Diff line number Diff line change 11#ifndef MAIN_H
22#define MAIN_H
3+ #include <unistd.h>
34#include <stdarg.h>
45#include <string.h>
56#define MIN (x , y ) (((x) < (y)) ? (x) : (y))
@@ -9,8 +10,8 @@ int _printf(const char *format, ...);
910int print_char (va_list );
1011int print_string (va_list );
1112int p_func (va_list , char );
12- void print_error (char * );
1313int parse_format (const char * );
14+ int rot13 (va_list );
1415
1516void * alloc (size_t );
1617char * int_to_string (long );
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ int parse_format(const char *fmt)
2222 /* char fmt[i] does not denote allowed specifier */
2323 if (fmt [i + 1 ] != 'c' && fmt [i + 1 ] != 's' && fmt [i +
2424 1 ] != '%' && fmt [i + 1 ] != 'd' && fmt [i
25- + 1 ] != 'i' )
25+ + 1 ] != 'i' && fmt [ i + 1 ] != 'R' )
2626 {
2727 ret_val = 0 ;
2828 break ;
Original file line number Diff line number Diff line change 1+ #include "main.h"
2+
3+ /**
4+ * rot13 - prints the rotated position of a string
5+ * @ap: String to rotate
6+ * Description: Rotates each character of a string to
7+ * the next thirteenth position in the alphabet.
8+ * Return: char printed to stdout.
9+ */
10+ int rot13 (va_list ap )
11+ { char * str = NULL ;
12+ char c ;
13+ int count = 0 ;
14+
15+ str = va_arg (ap , char * );
16+ while (* str )
17+ {
18+ if (* str >= 97 && * str <= 109 ) /* Rotates a - m to n - z */
19+ {
20+ c = * str + 13 ;
21+ count += write (1 , & c , 1 );
22+ }
23+ if (* str >= 110 && * str <= 122 ) /* Rotates n - z to a - m */
24+ {
25+ c = * str - 13 ;
26+ count += write (1 , & c , 1 );
27+ }
28+ if (* str >= 65 && * str <= 77 ) /* Rotates A - M to N - Z */
29+ {
30+ c = * str + 13 ;
31+ count += write (1 , & c , 1 );
32+ }
33+ if (* str >= 78 && * str <= 90 ) /* Rotates N - Z to A - M */
34+ {
35+ c = * str - 13 ;
36+ count += write (1 , & c , 1 );
37+ }
38+ * ++ str ;
39+ }
40+ return (count );
41+ }
You can’t perform that action at this time.
0 commit comments