- #1
charmedbeauty
- 271
- 0
Homework Statement
I am trying to write up code to reverse the order of a string i.e.
input: and
output: dna
For some reason I am getting this compiling warning but I don't know what's wrong with my code...
Homework Equations
The Attempt at a Solution
Code:
#include <stdio.h>
#include <string.h>
#define MAX_LENGTH 20
int main(int argc, char * argv[]){
char s[MAX_LENGTH];
printf("Enter String\n");
if( fgets(s,MAX_LENGTH,stdin) != NULL){
tnirp(s);
}
// original string
printf("\n, %s",s);
// the number of characters in a string
int i = 0;
while(s[i] != 0){
i++;
}
// Reverse string
printf("\n");
int idx;
for(idx = 0;idx < i;){
i--; // I place this here instead of in the for loop,
// because the for loop will subtract 1 from i
// before 'string' can even begin to print, thus
// the last char will not be printed.
printf("%c", s[i]);
}
return 0;
and this is the compiler warning
warnings being treated as errors
In function ‘main’:
warning: implicit declaration of function ‘tnirp’
any help is great!