Skip to content

Instantly share code, notes, and snippets.

@CompaqDisc
Created January 31, 2019 06:41
Show Gist options
  • Save CompaqDisc/dec6da2e7fc5eed187280c0a04debd7d to your computer and use it in GitHub Desktop.
Save CompaqDisc/dec6da2e7fc5eed187280c0a04debd7d to your computer and use it in GitHub Desktop.
Just a diff...
--- test-old.cc 2019-01-30 22:49:33.481304795 -0700
+++ test.cc 2019-01-30 23:39:32.564553393 -0700
@@ -69,13 +69,13 @@
int main()
{
- const int maxLength = 100;
+ const int maxLength = 101;
char inputChar = '\0';
do
{
printf("Type a string of text:\n");
- char *buffer = calloc(maxLength, sizeof(char));
+ char *buffer = (char*) calloc(maxLength, sizeof(char));
fgets(buffer, maxLength, stdin);
printf("\n");
@@ -96,14 +96,15 @@
printStringAsTriangle(buffer);
printf("\n");
- printf("Length of string: %i\n", strlen(buffer));
+ printf("Length of string: %li\n", strlen(buffer)-1);
printf("Type another string? (y/n)\n");
- inputChar = getchar();
+ scanf(" %c", &inputChar);
clearInputBuffer();
+ free(buffer);
} while (inputChar == 'y');
- return 1;
+ return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment