Why is this printing one empty line at the beginning of the output? \n is only after %s... Help please, I'm so frustrated.
if(argc > 1){
while(r!=NULL){
r = fgets(str, MAXL, stdin);
if(r==NULL){
return 0;
}
if (*argv[1] == 'i'){
char *invP = inv(r);
printf("%s\n", invP);
free(invP);
}
inv() is:
char* inv(char* C){
int length = 0;
int i;
for(i = 0; C[i]!='\0'; i++){
length++;
}
char *inverted;
inverted = malloc(length+1);
inverted[length] = '\0';
char* invP = inverted;
int j = 0;
for(i = length - 1; i >= 0; i--){
inverted[j] = C[i];
j++;
}
return invP;
}
It doesn't have any print on it, dunno why is this happening.