-
-
Save CraigRodrigues/87da838e4d9102af3b781001f763833b to your computer and use it in GitHub Desktop.
CS50x Coding Contest 2016 - Punctuation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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