Hey everyone,

I have a job interview coming up and despite the fact that most of the job is in C++, they want me to do the interview test in C which I have no experience in, not to mention my C++ is kinda rusty.

Now I would normally have no problem learning C on my own, but my test is in two days so I just need to be able to get past that so I can start refreshing on my C++ and learning C. Of course I don't want the code outright, I much prefer to figure stuff out but any help pointing me in the right direction would be much appreciated.

Now on to the problem:

They want a simple program that accepts a sentence input by the user then:

1. Displays the sentence. (Already got this part >.>)
2. Reverses the words. (ex. "Hi you guys" into "guys you Hi")
3. Alphabetize the letters in each word. (ex. "Hi you guys" into "Hi ouy gsuy")

Keep in mind, I just started learning C today so I know only the very basic commands and syntax. I really wish I would have kept up with my programming after graduating. :\

Ok, I'm not at home so I don't have a compiler handy but I was thinking something like this for alphabetizing the letters within the words:

int i, j;     
   char str[100]; 
   char temp;    

   printf("Please enter a sentence: ");
   fgets( str , 100 , stdin );

   int len = strlen(str);
   
   for(j = 0; j < len; j++)
   {
      for(i = 0; i < len && i+1 != " " || "\0" && i != " " || \0; i++)
      {
	 if(str[i] < str[i+1])
	 {
	    temp = str[i+1];
	    str[i+1] = str[i];
	    str[i] = temp;
	 }
      }
   }

And probably a similar loop to reverse the words back afer reversing the entire string.

This article has been dead for over six months. Start a new discussion instead.