Skip to content

Commit

Permalink
Updated get_flags.c file
Browse files Browse the repository at this point in the history
  • Loading branch information
godswillubah committed Mar 28, 2023
1 parent 13e1b59 commit 168a838
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions get_flags.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "main.h"

/**
* get_flags - Calculates active flags
* @format: Formatted string in which to print the arguments
* @i: take a parameter.
* Return: Flags:
* Written by Kebron Araya and Godswill Ubah.
int get_flags(const char *format, int *i)
{
/* - + 0 # ' ' */
/* 1 2 4 8 16 */
int j, curr_i;
int flags = 0;
const char FLAGS_CH[] = {'-', '+', '0', '#', ' ', '\0'};
const int FLAGS_ARR[] = {F_MINUS, F_PLUS, F_ZERO, F_HASH, F_SPACE, 0};

for (curr_i = *i + 1; format[curr_i] != '\0'; curr_i++)
{
for (j = 0; FLAGS_CH[j] != '\0'; j++)
if (format[curr_i] == FLAGS_CH[j])
{
flags |= FLAGS_ARR[j];
break;
}

if (FLAGS_CH[j] == 0)
break;
}

*i = curr_i - 1;

return (flags);
}

0 comments on commit 168a838

Please sign in to comment.