1st CS homework, Almost done!
So close, yet so far!
-This is the last part of a long homework set. It asks for a program that:
-Asks the user to insert a word
-Reads the string
-Converts all the characters to lowercase
-prints the string characters in reverse order
I had it working up until the last part, reversing the order. Please excuse the horribleness of the follow code, I'm brand new at this:
Code:
#include<stdio.h>
#include<string.h>
int main() {
char str1[100];
char name [100];
printf("Enter your first name:\n");
fgets(str1, sizeof(str1), stdin);
sscanf(str1, "%s", name);
int i = 0;
while (i <= strlen(name)){
if((name[i] >= 'A') && (name[i] <= 'Z'))
name[i] = name[i] + 32;
i++;
}
char eman[100];
int y;
i=0;
while (i <= strlen(name)) {
y = strlen(name) - i;
name[y] = eman[i];
i++;
}
printf("%s", eman);
return(0);
}
I feel like I'm on the right track that I need eman[i] to equal name[strlen(name)-i], but having problems representing that effectively.
Any help is appreciated. Also, any style tips, gonna have to start making the programs from this set look presentable lol