Skip to content

Commit ef7103e

Browse files
committed
hat prints every other character of a string, starting with the first character, followed by a new line.
1 parent b528f04 commit ef7103e

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

0x05-pointers_arrays_strings/6-main.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include "main.h"
2+
3+
/**
4+
* main - check the code
5+
*
6+
* Return: Always 0.
7+
*/
8+
int main(void)
9+
{
10+
char *str;
11+
12+
str = "0123456789";
13+
puts2(str);
14+
return (0);
15+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include "main.h"
2+
/**
3+
* puts2 - func that prints 1 char/2 of a string, followed by a new line.
4+
* @str: declaration of str and paramters for the function puts2
5+
* Return: Always 0.
6+
*/
7+
void puts2(char *str)
8+
{
9+
int c;
10+
char l;
11+
12+
for (c = 0; str[c] != 0; c++)
13+
{
14+
if (c % 2 == 0)
15+
{
16+
l = str[c];
17+
_putchar(l);
18+
}
19+
}
20+
_putchar('\n');
21+
}

0 commit comments

Comments
 (0)