Reversing program

Reversing program

Post by AppAttacker on Mon Nov 23, 2015 5:55 pm
([msg=90719]see Reversing program[/msg])

So I've been reading and practicing C for a few months now on and off, and I finally decided to start hacking away at some code. So I googled for some simple programs to try writing and the first one was a program to reverse whatever the user input is. Now I don't want any answers but if you could maybe clue me in if I'm using any functions wrong or something.

the code is: (ignore the printf of the strlen its for debugging)
Code: Select all
#include <stdio.h>
#include <string.h>

int main(int argc, char *argv[]) {

  char command[100];

  printf("please enter string: ");
  fgets(command, 100, stdin);
 
  //printf("%d", strlen(command));
 
  int ha = strlen(command);
 
  while(1){
    if(!strcmp(command,"quit")) {
 
      for(int i = 0; i < ha; i++) {
   int str = strlen(command) - i;
   puts(command[str]);
      }
    }
    else {
     exit(0);
    }
   
    printf("please enter string: ");
    fgets(command, 100, stdin);
  }
return 0;
}


It compiles with no warnings or errors but when ran after entering some input it gives me a segmentation fault.
any help is very much appreciated!



Ok nevermind I finished it THANK YOU STACKOVERFLOW
I will be quiet, and I shall hear ALL
AppAttacker
New User
New User
 
Posts: 6
Joined: Sat Nov 21, 2015 2:42 pm
Blog: View Blog (0)


Return to C and C++

Who is online

Users browsing this forum: No registered users and 0 guests