summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAaron Ball <nullspoon@iohq.net>2015-10-01 23:30:36 -0600
committerAaron Ball <nullspoon@iohq.net>2015-10-01 23:30:36 -0600
commit4badddd80e18697830cecf19bbc5bbc5e6adf0d7 (patch)
tree1a62f7fe4fe5ed647d792dd434c6ac2330b39f64 /src
parentb8de26c118b09ee8bd763fa12111ea9d20b14684 (diff)
downloadpalindrome_finder-4badddd80e18697830cecf19bbc5bbc5e6adf0d7.tar.gz
palindrome_finder-4badddd80e18697830cecf19bbc5bbc5e6adf0d7.tar.xz
Converted most data types to unsigned
Unsigned are faster and since we never go negative (most of the time), this isn't a problem and it provides support for much larger files.
Diffstat (limited to 'src')
-rw-r--r--src/main.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/main.c b/src/main.c
index 7bdaba0..65db782 100644
--- a/src/main.c
+++ b/src/main.c
@@ -9,10 +9,10 @@
//
// @return int Is a palindrome (1) or not (0)
//
-char is_palindrome(char* str, long len) {
+char is_palindrome(char* str, int len) {
//long len;
- long i = 0;
- long n = len;
+ int i = 0;
+ int n = len;
// This handles comparisons of odd and even length strings
while(n - i > 0) {
@@ -33,18 +33,18 @@ char is_palindrome(char* str, long len) {
// @param data Data chunk to search for the largest palindrome
//
void find_largest_palindromes(char* data) {
- int largest_start = 0;
- int largest_end = 0;
+ unsigned int largest_start = 0;
+ unsigned int largest_end = 0;
int largest_len = 0;
// get length
- int len = 0;
+ unsigned int len = 0;
while(data[len] != '\0')
len++;
- int start;
- int end = len;
- int palindrome;
+ long start;
+ long end = len;
+ unsigned int palindrome;
while(end > 0) {
// Moving the start index
start = 0;
@@ -56,7 +56,7 @@ void find_largest_palindromes(char* data) {
palindrome = is_palindrome(&data[start], end - start);
if(palindrome == 1) {
// Update the largest if this one is bigger
- int curlen = end - start;
+ unsigned int curlen = end - start;
if(curlen > largest_len) {
largest_len = curlen;
largest_start = start;
@@ -120,7 +120,7 @@ int main(int argc, char *argv[]) {
printf("Allocating memory\n");
// Allocate array for file contents
char data[flen + 1];
- int i = 0;
+ unsigned int i = 0;
char c;
printf("Reading data to memory\n");
while((c = fgetc(f)) != EOF) {

Generated by cgit