PLease help me !!
how can i uppercase the half only of the string and the half is in lower case??

PLease help me !!
how can i uppercase the half only of the string and the half is in lower case??

include string.h, and ctype.h, and use the strlen(string) function to help you know the length of your string. Then divide by two. Add one if the length is odd (13/2=6, but the other half will be 7, not 6 char's in length).

Then use a for loop from 0 to half-1:

for(i=0;i<half;i++)
  charArray[i] = toupper(charArray[i]);

Use similar logic for the other half, and tolower(), in the same way, starting at half and ending at length of the string in charArray[].

The way it works on the forum, is that you need to post up your code FIRST, and state what the problem is, if you want help that includes specific code.

And always put your code between code tags (click on

icon in the editor window)[code]
icon in the editor window)

thank you:)
this is my code:

#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include<string.h>
#include<ctype.h>
#include<dos.h>

char word[289];
char *str1,*str2;
char *rev;
char *upper;
char *lower;
char *dup;
char choice[3];
int a,b,x,y,z,j,temp;


void main()
{
 input:
 clrscr();
 printf("ENTER A WORD:");
 gets (word);
 printf("\nYOUR WORD IS:");
 puts (word);
 menu:
 dup=strdup(word);
 for(z=1;z<=5;z++)
 {
 printf( "\n\n1:REVERSE\n2:ACSENDING ORDER \n3:DESCENDING ORDER\n4:UPPERCASE HIGHER HALF\n5:UPPERCASE LOWER HALF\n:");
 gets (choice);
 printf("\nYOUR CHOICE:");
 puts(choice);

   switch(choice[y])
	{
	case'1': {
		 rev= strrev(word);
		 printf("\n\t\t\t\REVERSE WORD:%s",rev);
		 getch();
		 clrscr();
		 printf("\nYOUR WORD IS:");
		 puts (dup);
		 break;
		 }


	case '2':{
		   for(a=0;a<strlen(word);a++)

		  {

		    for(b=0;b<strlen(word);b++)

		  {

		  if(word[a]<word[b])

		    {
		  temp=word[a];
		  word[a]=word[b];
		  word[b]=temp;
		  printf("\n\t\t\t\RESULT:");
		  puts(word);
	}

	}

	}

	       getch();
		clrscr();
		 printf("\nYOUR WORD IS:");
		 puts (dup);
		 break;
		 }



	case'3':{
		  for(a=0;a<strlen(word);a++)
		 {
		  for(b=0;b<strlen(word);b++)
		{
		if(word[a]>word[b])
		 {
		  temp=word[a];
		  word[a]=word[b];
		  word[b]=temp;
		  printf("\n\t\t\t\RESULT:");
		  puts( word);
		 }
		 }
		 }
		 getch();
		 clrscr();
		 printf("\nYOUR WORD IS:");
		 puts (dup);
	break;
       }
       case '4': {
		   if(strlen(word)%2==0)
		   {



}
}
}

@adak
there is no changes when i try the code that you gave me :(

1) Please format your code so we can read it properly.
2) Do not use gets() , here's why.
3) main() is not a void function. See this.
4) To get help, you need to show an attempt. There is no attempt in this code for 4 & 5.

It's really odd how having no code for upper or lower case changing, means no result. ;)

#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include<string.h>
#include<ctype.h>
#include<dos.h>

char word[289];
char *str1,*str2;
char *rev;
char *upper;
char *lower;
char *dup;
char choice[3];
int a,b,x,y,i,h,z,j,temp;


void main()
{
 input:
 clrscr();
 printf("ENTER A WORD:");
 gets (word);
 printf("\nYOUR WORD IS:");
 puts (word);
 dup=strdup(word);
 menu:
 for(z=1;z<=5;z++)
 {
 printf( "\n\n1:REVERSE\n2:ACSENDING ORDER \n3:DESCENDING ORDER\n4:UPPERCASE HIGHER HALF\n5:UPPERCASE LOWER HALF\n:");
 gets (choice);
 printf("\nYOUR CHOICE:");
 puts(choice);

   switch(choice[y])
    {
    case'1': {
         rev= strrev(word);
         printf("\n\t\t\t\REVERSE WORD:%s",rev);
         getch();
         clrscr();
         printf("\nYOUR WORD IS:");
         puts (dup);
         break;
         }


    case '2':{
           for(a=0;a<strlen(word);a++)

          {

            for(b=0;b<strlen(word);b++)

          {

          if(word[a]<word[b])

            {
          temp=word[a];
          word[a]=word[b];
          word[b]=temp;
          printf("\n\t\t\t\RESULT:");
          puts(word);
    }

    }

    }

           getch();
        clrscr();
         printf("\nYOUR WORD IS:");
         puts (dup);
         break;
         }



    case'3':{
          for(a=0;a<strlen(word);a++)
         {
          for(b=0;b<strlen(word);b++)
        {
        if(word[a]>word[b])
         {
          temp=word[a];
          word[a]=word[b];
          word[b]=temp;
          printf("\n\t\t\t\RESULT:");
          puts( word);
         }
         }
         }
         getch();
         clrscr();
         printf("\nYOUR WORD IS:");
         puts (dup);
    break;
       }
       case '4': {
           if(strlen(word)%2==0)
           {
             for(i=0;i<strlen(word)/2;i++)
             word[i]==toupper(word[i]);
             {
             for(h=0;h<strlen(word)/2;h++)
             word[h]==tolower(word[h]);

             printf("UPPERCASE HIGHER HALF:");
             puts(word);
             }
             }
            if(strlen(word)%2!=0)
           {
             for(i=0;i<strlen(word)/2+1;i++)
             word[i]==toupper(word[i]);
             {
             for(h=0;h<strlen(word)/2+1;h++)
             word[h]==tolower(word[h]);

             printf("UPPERCASE HIGHER HALF:");
             puts(word);
             }
             }
                    getch();
            clrscr();
            printf("\nYOUR WORD IS:");
            puts (dup);
            break;
           }



}
}
}

1) Please format your code so we can read it properly.
2) Do not use gets() , here's why.
3) main() is not a void function. See this.
4) To get help, you need to show an attempt. There is no attempt in this code for 4 & 5.

#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include<string.h>
#include<ctype.h>
#include<dos.h>

char word[289];
char *str1,*str2;
char *rev;
char *upper;
char *lower;
char *dup;
char choice[3];
int a,b,x,y,i,h,z,j,temp;


void main()
{
 input:
 clrscr();
 printf("ENTER A WORD:");
 gets (word);
 printf("\nYOUR WORD IS:");
 puts (word);
 dup=strdup(word);
 menu:
 for(z=1;z<=5;z++)
 {
 printf( "\n\n1:REVERSE\n2:ACSENDING ORDER \n3:DESCENDING ORDER\n4:UPPERCASE HIGHER HALF\n5:UPPERCASE LOWER HALF\n:");
 gets (choice);
 printf("\nYOUR CHOICE:");
 puts(choice);

   switch(choice[y])
	{
	case'1': {
		 rev= strrev(word);
		 printf("\n\t\t\t\REVERSE WORD:%s",rev);
		 getch();
		 clrscr();
		 printf("\nYOUR WORD IS:");
		 puts (dup);
		 break;
		 }


	case '2':{
		   for(a=0;a<strlen(word);a++)

		  {

		    for(b=0;b<strlen(word);b++)

		  {

		  if(word[a]<word[b])

		    {
		  temp=word[a];
		  word[a]=word[b];
		  word[b]=temp;
		  printf("\n\t\t\t\RESULT:");
		  puts(word);
	}

	}

	}

	       getch();
		clrscr();
		 printf("\nYOUR WORD IS:");
		 puts (dup);
		 break;
		 }



	case'3':{
		  for(a=0;a<strlen(word);a++)
		 {
		  for(b=0;b<strlen(word);b++)
		{
		if(word[a]>word[b])
		 {
		  temp=word[a];
		  word[a]=word[b];
		  word[b]=temp;
		  printf("\n\t\t\t\RESULT:");
		  puts( word);
		 }
		 }
		 }
		 getch();
		 clrscr();
		 printf("\nYOUR WORD IS:");
		 puts (dup);
	break;
       }
       case '4': {
		   if(strlen(word)%2==0)
		   {
		     for(i=0;i<strlen(word)/2;i++)
		     word[i]==toupper(word[i]);
		     {
		     for(h=0;h<strlen(word)/2;h++)
		     word[h]==tolower(word[h]);

		     printf("UPPERCASE HIGHER HALF:");
		     puts(word);
		     }
		     }
		    if(strlen(word)%2!=0)
		   {
		     for(i=0;i<strlen(word)/2+1;i++)
		     word[i]==toupper(word[i]);
		     {
		     for(h=0;h<strlen(word)/2+1;h++)
		     word[h]==tolower(word[h]);

		     printf("UPPERCASE HIGHER HALF:");
		     puts(word);
		     }
		     }
                    getch();
		    clrscr();
		    printf("\nYOUR WORD IS:");
		    puts (dup);
		    break;
		   }



}
}
}
commented: EDIT your posts, don't just post again. -3

And....?

Explanations help.

I erred on the strlen(word)%2==0 idea. Not necessary, please drop it.

Here's your code, with a few tweaks. The tweaks are right below the code that needs tweaking:

#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include<string.h>
#include<ctype.h>
#include<dos.h>


/*All these global variables, let's remove and make them local variables instead. Seems a PITA maybe, but it pays big dividends in programming.

char word[289];
char *str1,*str2;
char *rev;
char *upper;
char *lower;
char *dup;
char choice[3];
int a,b,x,y,i,h,z,j,temp;
*/

//void main()
int main(void) //<===== Always int main, never void
{
 int len, i, j;
 char dup[250]; //nice and big :)
 char word[250];  //  ditto
 char choice;
 //input:  //use functions and logic, and not labels 95% of the time.
  
 //clrscr(); //this crashes my IDE, immediately
 printf("\n\n");  //gives the separation we need
 printf("ENTER A WORD:");
 gets (word); //unsafe! but we'll use it for now
 printf("\nYOUR WORD IS:");
 puts (word);
 //dup=strdup(word);
 strcpy(dup, word);
 len = strlen(word);
 //menu:
 //for(z=1;z<=5;z++)
 do 
 {
   printf( "\n\n1:REVERSE\n2:ACSENDING ORDER \n3:DESCENDING ORDER\n\4:UPPERCASE HIGHER HALF\n5:UPPERCASE LOWER HALF\n:");
  gets (choice);
  printf("\nYOUR CHOICE:");
  puts(choice);

  switch(choice[y])
  {
    case'1': {
      rev= strrev(word);
      printf("\n\t\t\t\REVERSE WORD:%s",rev);
		 getch();
      // clrscr();
      printf("\nYOUR WORD IS:");
      puts (dup);
      break;
    }
    case '2':{
     for(a=0;a<strlen(word);a++)
     {
       for(b=0;b<strlen(word);b++)
       {
	  if(word[a]<word[b])
          {
	     temp=word[a];
	     word[a]=word[b];
	     word[b]=temp;
	     printf("\n\t\t\t\RESULT:");
	     puts(word);
	  }
        }
      }

      getch();
      //clrscr();
      printf("\nYOUR WORD IS:");
      puts (dup);
      break;
    }
    case'3':{
      for(a=0;a<strlen(word);a++)
      {
		  for(b=0;b<strlen(word);b++)
		{
		if(word[a]>word[b])
		 {
		  temp=word[a];
		  word[a]=word[b];
		  word[b]=temp;
		  printf("\n\t\t\t\RESULT:");
		  puts( word);
		 }
		 }
		 }
		 getch();
		 clrscr();
		 printf("\nYOUR WORD IS:");
		 puts (dup);
	break;
       }
       case '4': {
	   if(strlen(word)%2==0)
		   {
		     for(i=0;i<strlen(word)/2;i++)
		     word[i]==toupper(word[i]);
		     {
		     for(h=0;h<strlen(word)/2;h++)
		     word[h]==tolower(word[h]);

		     printf("UPPERCASE HIGHER HALF:");
		     puts(word);
		     }
		     }
		    if(strlen(word)%2!=0)
		   {
		     for(i=0;i<strlen(word)/2+1;i++)
		     word[i]==toupper(word[i]);
		     {
		     for(h=0;h<strlen(word)/2+1;h++)
		     word[h]==tolower(word[h]);

		     printf("UPPERCASE HIGHER HALF:");
		     puts(word);
		     }
		     }
                    getch();
		    clrscr();
		    printf("\nYOUR WORD IS:");
		    puts (dup);
		    break;
		   }



  }while(choice != '0');
  }
  printf("\n\n\t\t\t    press enter when ready");
  (void) getchar();
  return 0;
}

Lots of things wrong with the code, but the important thing right now, is to make it readable, and get the basic flow right. Then work with the details of each switch statement, one at a time, to make it right.

This is an example of what I had in mind for the toupper and tolower part:

#include <stdio.h>
#include <string.h>
#define SIZE 100

int main() {
  int i, n, len;
  char s[SIZE];
  printf("\n\n");
  fgets(s, sizeof(s), stdin);
  printf("\n%s", s);
  len = strlen(s);
  //fgets() is a great input technique, but it adds a newline char
  //that I don't want to include (although I could).
  if(s[len-1]=='\n') //find the newline near the end of the phrase
    s[len-1]='\0';   //and replace it with the end of string char
  --len;             //reduce the length of the string by one
  for(i=0;i<len;i++) {
    if(i < len/2) 
      s[i] = toupper(s[i]);
    else
      s[i] = tolower(s[i]);
  }
  printf("\n%s", s);
  printf("\n\n\t\t\t     press enter when ready");
  (void) getchar(); 
  return 0;
}

i thank you all for all your help i've made it already :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.