I have a loop that has to go from j to 0 (inclusively). My j
variable is of type size_t
which is usually unsigned.
My code:
#include<stdio.h>
#include<conio.h>
#define SIZE 100
int main(){
char str[SIZE];
size_t i=0;
size_t j;
puts("Enter any string");
scanf("%s",str);
while(str[i]!='\0'){
i++;
}
for(j=i-1;j>=0;j--){
printf("%c",str[j]);
}
getch();
return 0;
}
I get an infinite loop. If I remove the equality of zero it outputs the reverse of string without the first letter. so what's the problem here?