Skip to content

Instantly share code, notes, and snippets.

@tomcha
Created March 17, 2015 10:48
Show Gist options
  • Select an option

  • Save tomcha/40f41f2e526a5ce6c753 to your computer and use it in GitHub Desktop.

Select an option

Save tomcha/40f41f2e526a5ce6c753 to your computer and use it in GitHub Desktop.
1-19
#include <stdio.h>
#define MAXCHAR 100
void reversd(int i, char s[], char r[]);
void cleararray(char array[]);
int main(){
char s[MAXCHAR];
char r[MAXCHAR];
int c;
int i = 0;
while((c = getchar()) != EOF){
if(c != '\n'){
s[i] = c;
i++;
}else{
reversd(i, s, r);
printf("%s\n", r);
i = 0;
cleararray(s);
cleararray(r);
}
}
}
void reversd(int i, char s[], char r[]){
i--;
int j;
for(j = 0; i >= 0; j++){
r[j] = s[i];
i--;
}
}
void cleararray(char array[]){
for(int i = 0; i < MAXCHAR; i++){
array[i] = '\0';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment