Skip to content

Instantly share code, notes, and snippets.

@CraigRodrigues CraigRodrigues/punctuation.c Secret
Last active Jul 30, 2016

What would you like to do?
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(". ");
printf("%c", sentence[i]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.