Skip to content

Instantly share code, notes, and snippets.

@reagent
Created November 14, 2012 05:47
Show Gist options
  • Save reagent/4070534 to your computer and use it in GitHub Desktop.
Save reagent/4070534 to your computer and use it in GitHub Desktop.
#include <stdlib.h>
#include <string.h>
char *
str_upcase(char *source)
{
int i = 0;
int shift = 0;
char ch = '\0';
int buffer_size = strlen(source) + 1;
char *output = malloc(buffer_size * sizeof(char));
for (i = 0; i < buffer_size; i++) {
ch = *(source + i);
if (ch >= 97 && ch <= 122) {
shift = -32;
} else {
shift = 0;
}
*(output + i) = ch + shift;
}
return output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment