Skip to content

Instantly share code, notes, and snippets.

@CraigRodrigues
Last active July 30, 2016 14:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CraigRodrigues/87da838e4d9102af3b781001f763833b to your computer and use it in GitHub Desktop.
Save CraigRodrigues/87da838e4d9102af3b781001f763833b to your computer and use it in GitHub Desktop.
CS50x Coding Contest 2016 - Punctuation
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "cs50.h"
int main(void)
{
string sentence = GetString();
int period_flag = 0;
//loop through the sentence given
for (int i = 0; i < strlen(sentence); i++)
{
if (period_flag == 1) //marker to see if we have run across a period or not
{
printf("%c", toupper(sentence[i])); //if we have then next character must be uppercase
period_flag = 0; //reset flag for next period
}
else if (sentence[i] == ',')
printf(", ");
else if (sentence[i] == '.')
{
period_flag = 1;
printf(". ");
}
else
printf("%c", sentence[i]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment