Skip to content

Instantly share code, notes, and snippets.

@jkwill87
Last active January 21, 2016 02:29
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 jkwill87/6c72e4db97dffdc7d0b5 to your computer and use it in GitHub Desktop.
Save jkwill87/6c72e4db97dffdc7d0b5 to your computer and use it in GitHub Desktop.
CIS2500 - lab 01 - uppercase
#include <stdio.h>
#include "uppercase.h"
int main(int argc, char** argv) {
FILE* textFile;
char text[BUFFER];
/* Open text file */
textFile = fopen(argv[1], "r");
if (textFile) {
fgets(text, BUFFER, textFile);
} else {
printf("Could not open text file. Exiting.");
return (1);
}
/* Print text before transformation */
printf("Text Before:\n");
printf("%s\n", text);
/* Transform text, print results */
uppercase(text);
printf("Text After:\n");
printf("%s\n", text);
return 0;
}
void uppercase(char text[]) {
char currentChar;
int i = 0;
do {
currentChar = text[i];
if (currentChar >= 'a' && currentChar <= 'z') {
text[i] -= 32;
}
i++;
} while (text[i]);
fclose(textFile);
return;
}
#ifndef __JWILLI19__HELLO__
#define __JWILLI19__HELLO__
#define BUFFER 500
void uppercase(char text[]);
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment