Add files via upload

This commit is contained in:
Christian Bender 2018-01-24 22:24:43 +01:00 committed by GitHub
parent 75f7866320
commit c6cb7c8362
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 160 additions and 0 deletions

View File

@ -0,0 +1,87 @@
#include <string.h>
#include <stdio.h>
#include <ctype.h>
char *abbreviate(const char *phrase)
{
char str[80];
strcpy(str, phrase);
char *p_str = str;
static char acr[80];
strcpy(acr, "");
/* for counting the words */
int counter = 0;
/* for position the words */
int index = 0;
/* for -loop variable */
int i = 0;
/*
counts the empty-characters.
for determine the number of words
*/
while (p_str && (i < 80))
{
if (*p_str == ' ')
{
counter++;
}
if (i < 80)
{
p_str++;
i++;
}
}
i = 0;
counter++;
char words[counter][80];
/* initalizes words-array with empty strings */
for (i = 0; i < counter; i++)
{
strcpy(words[i],"");
}
/* rewind string */
p_str = str;
char *p_start = p_str;
/* collects each word in array 'words' */
while (p_str && (i <= 80))
{
if (*p_str == ' ')
{
*p_str = '\0';
strncat(words[index], p_start, 80);
index++;
p_start = p_str + 1;
}
if (i <= 80)
{
p_str++;
i++;
}
}
/* adds the last word */
*p_str = '\0';
strncat(words[index], p_start, 80);
index++;
/* builds the actual acronym */
for (i = 0; i < index; i++)
{
/* capitalize the first character */
words[i][0] = toupper(words[i][0]);
words[i][1] = '\0';
strcat(acr, words[i]);
}
return acr;
}

View File

@ -0,0 +1,6 @@
#ifndef ACRONYM_H
#define ACRONYM_H
char *abbreviate(const char *phrase);
#endif

View File

@ -0,0 +1,7 @@
#include "hello_world.h"
const char *hello(void)
{
/* string is pointer of the first character */
return "Hello, World!";
}

View File

@ -0,0 +1,6 @@
#ifndef HELLO_WORLD_H
#define HELLO_WORLD_H
const char *hello(void);
#endif

View File

@ -0,0 +1,46 @@
#include <stdbool.h>
#include <string.h>
/*
is_isogram: returns true if the given string a isogram, otherwise false.
*/
bool is_isogram(const char phrase[])
{
/* use 'unsigned' because of the function strlen(...) */
unsigned int i = 0;
unsigned int j = 0;
/* the current read character in the first for-loop */
char current_char = ' ';
/* return status */
bool status = true;
/* contains the length of the given string */
unsigned int len_phrase = strlen(phrase);
for (i = 0; i < len_phrase; i++ )
{
current_char = phrase[i];
/* makes sure the current character has no repetition */
for (j = i+1; j < len_phrase; j++)
{
if (current_char == phrase[j])
{
status = false;
/*
because the given string is none isogram.
that means we can exit the nested for-loop.
*/
goto end;
}
}
}
/* exit label */
end:
return status;
}

View File

@ -0,0 +1,8 @@
#ifndef ISOGRAM_H
#define ISOGRAM_H
#include <stdbool.h>
bool is_isogram(const char phrase[]);
#endif