This is the assignment
Write a program that
5.1. Asks the user to insert a word
5.2. Reads the string from standard input (assume the work does not have more than 100 characters)
5.3. Converts all the characters to lower case.
5.4. Prints the string characters in reverse order. For example, if the input is "Luke", the program should print "ekul".
Here's what I have so far (without attempting 5.4)
#include<stdio.h>
#include<string.h>
char str1[100];
char str2[100];
char str3[100]; //for the 3rd part of the problem
int x;
int y;
int main()
{
printf("Enter your first name:\n");
fgets(str1, sizeof(str1), stdin);
sscanf(str1, "%s", str1); //Saving the input as str1
str1[x]=y; /* this is where I'm confused, I don't know how to work with the array position variable vs. the array value... */
while((y >= 'A') && (y <= 'Z')) { /*my shot in the dark on which loop to use and how to use it*/
y= y+32;
str1[x++];
break;
}
strcpy(str2, str1); //because... I don't know...
printf("Your name is %s", str1);
return(0);
}
I assume we can't use other libraries. I know there are functions that will convert to upper/lower case and I'm fairly sure we won't get credit for using them.
So it's probably obvious that (I have no idea what I'm doing) I don't know how to work with strings! Our 10 minute run down on strings didn't cover reassigning values to elements. The textbook doesn't get this in-depth within the chapters we've covered, reading ahead hasn't helped, reading another C book I have hasn't helped, I can't find anything helpful through google (everyone suggests using different libraries)...
tldr: I'm very frustrated and would appreciate any help anyone might offer.


Sign In
Create Account


Back to top









