Commit 95b479d

mo k <mo@mokhan.ca>
2012-02-18 03:13:03
trying to figure out why strlen isn't returning the correct length.
1 parent 72ccaac
Changed files (2)
src/main.c
@@ -3,35 +3,32 @@
 #include <string.h>
 
 void reverse(char* input){
-  char *begin, *end;
-  char tmp;
-  int i;
+  char *start, *end, tmp;
 
-  begin = &input[0];
+  start = input;
+  printf("%zu \n",strlen(input));
   end = &input[strlen(input)-1];
-  for (i = 0; i < strlen(input)-1; i++) {
-    if(begin == end) break;
+
+  while(start != end){
     tmp = *end;
-    *end = *begin;
-    *begin = tmp;
-    begin++;
-    end--;
+    *end = *start;
+    *start = tmp;
+    ++start;
+    if(start == end) break;
+    --end;
   }
 }
 
 int main(int argc, const char *argv[])
 {
-  unsigned char input[128];
-
-  /*printf("what is your name: ");*/
-  /*scanf("%s", input);*/
+  char input[128];
 
+  memset(&input, 0, sizeof(input)-1);
   printf("enter a string to reverse: ");
   scanf("%s", input);
 
   reverse(input);
   printf("%s", input);
 
-  /*printf("goodbye %s", input);*/
   return 0;
 }
makefile
@@ -1,4 +1,4 @@
 FILES = src/*.c
 
-rover: $(FILES)
-	gcc $(FILES) -o rover.out
+reverse: $(FILES)
+	cc $(FILES) -o reverse.out