Skip to content

Commit

Permalink
Amend the return type of function in raindrop
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashvith10 committed Apr 4, 2024
1 parent b69d5de commit 60d8f57
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#ifndef RAINDROPS_H
#define RAINDROPS_H

char *convert(char result[], int drops);
void convert(char result[], int drops);

#endif
```
Expand All @@ -32,7 +32,7 @@ static const sound_t SOUNDS[] = {

#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))

char *convert(char result[], int drops)
void convert(char result[], int drops)
{
for (size_t i = 0; i < ARRAY_SIZE(SOUNDS); i++) {
if (drops % SOUNDS[i].factor == 0) {
Expand All @@ -43,8 +43,6 @@ char *convert(char result[], int drops)
if (strlen(result) == 0) {
sprintf(result, "%d", drops);
}

return result;
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#ifndef RAINDROPS_H
#define RAINDROPS_H

char *convert(char result[], int drops);
void convert(char result[], int drops);

#endif
```
Expand All @@ -19,7 +19,7 @@ char *convert(char result[], int drops);
#include <stdio.h>
#include <string.h>

char *convert(char result[], int drops)
void convert(char result[], int drops)
{
if (drops % 3 == 0)
strcat(result, "Pling");
Expand All @@ -30,8 +30,6 @@ char *convert(char result[], int drops)

if (strlen(result) == 0)
sprintf(result, "%d", drops);

return result;
}
```
Expand Down
18 changes: 6 additions & 12 deletions exercises/practice/raindrops/.approaches/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ The key to solving Raindrops is to know if the input is evenly divisible by `3`,
#ifndef RAINDROPS_H
#define RAINDROPS_H

char *convert(char result[], int drops);
void convert(char result[], int drops);

#endif
```
Expand All @@ -37,7 +37,7 @@ char *convert(char result[], int drops);
#include <stdio.h>
#include <string.h>

char *convert(char result[], int drops)
void convert(char result[], int drops)
{
if (drops % 3 == 0)
strcat(result, "Pling");
Expand All @@ -48,8 +48,6 @@ char *convert(char result[], int drops)

if (strlen(result) == 0)
sprintf(result, "%d", drops);

return result;
}
```
Expand All @@ -64,7 +62,7 @@ For more information, check the [`if` statements approach][approach-if-statement
#ifndef RAINDROPS_H
#define RAINDROPS_H
char *convert(char result[], int drops);
void convert(char result[], int drops);
#endif
```
Expand All @@ -82,15 +80,13 @@ char *convert(char result[], int drops);
#include <stdio.h>
#include <string.h>

char *convert(char result[], int drops)
void convert(char result[], int drops)
{
sprintf(result, "%s%s%s", drops % 3 == 0 ? "Pling" : "",
drops % 5 == 0 ? "Plang" : "", drops % 7 == 0 ? "Plong" : "");

if (strlen(result) == 0)
sprintf(result, "%d", drops);

return result;
}
```
Expand All @@ -106,7 +102,7 @@ For more information, check the [`sprintf` functon approach][approach-sprintf].
#ifndef RAINDROPS_H
#define RAINDROPS_H
char *convert(char result[], int drops);
void convert(char result[], int drops);
#endif
```
Expand All @@ -132,7 +128,7 @@ static const sound_t SOUNDS[] = {

#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))

char *convert(char result[], int drops)
void convert(char result[], int drops)
{
for (size_t i = 0; i < ARRAY_SIZE(SOUNDS); i++) {
if (drops % SOUNDS[i].factor == 0) {
Expand All @@ -143,8 +139,6 @@ char *convert(char result[], int drops)
if (strlen(result) == 0) {
sprintf(result, "%d", drops);
}

return result;
}
```
Expand Down
11 changes: 2 additions & 9 deletions exercises/practice/raindrops/.approaches/sprintf/content.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#ifndef RAINDROPS_H
#define RAINDROPS_H

char *convert(char result[], int drops);
void convert(char result[], int drops);

#endif
```
Expand All @@ -19,20 +19,13 @@ char *convert(char result[], int drops);
#include <stdio.h>
#include <string.h>

#include "raindrops.h"

#include <stdio.h>
#include <string.h>

char *convert(char result[], int drops)
void convert(char result[], int drops)
{
sprintf(result, "%s%s%s", drops % 3 == 0 ? "Pling" : "",
drops % 5 == 0 ? "Plang" : "", drops % 7 == 0 ? "Plong" : "");

if (strlen(result) == 0)
sprintf(result, "%d", drops);

return result;
}
```
Expand Down
9 changes: 4 additions & 5 deletions exercises/practice/raindrops/.meta/example.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "raindrops.h"
#include "stdio.h"
#include "string.h"
#include <stdlib.h>

char *convert(char result[], int drops)
#include <stdio.h>
#include <string.h>

void convert(char result[], int drops)
{
if (drops % 3 == 0) {
strcat(result, "Pling");
Expand All @@ -19,5 +19,4 @@ char *convert(char result[], int drops)
sprintf(drops_string, "%d", drops);
strcat(result, drops_string);
}
return result;
}
2 changes: 1 addition & 1 deletion exercises/practice/raindrops/.meta/example.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef RAINDROPS_H
#define RAINDROPS_H

char *convert(char result[], int drops);
void convert(char result[], int drops);

#endif
2 changes: 1 addition & 1 deletion exercises/practice/raindrops/raindrops.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef RAINDROPS_H
#define RAINDROPS_H

char *convert(char result[], int drops);
void convert(char result[], int drops);

#endif

0 comments on commit 60d8f57

Please sign in to comment.