having problem with functions

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • zaacze
    New Member
    • Mar 2007
    • 11

    having problem with functions

    does anybody knows the answer to this? a function that take in an uppercase character parameter. The function returns the next uppercase character if lett is between 'A' and 'Y'. if let=='Z', the function returns 'A'... i tried to do it but after entering a letter, nothing happens... help pls.. need it so urgently....tha nks a lot!
  • Savage
    Recognized Expert Top Contributor
    • Feb 2007
    • 1759

    #2
    Hi,

    maybe if you could make char whit coresponding ASCII code for each character in depandance of char inputed
    and then increase it by one if it is beetwen A and Y or else set to 65 if the
    character is Z.

    Savage

    Comment

    • zaacze
      New Member
      • Mar 2007
      • 11

      #3
      thanks for the reply.. i do understand the logic about setting 'Z' to say, 65... but the thing is, i've tried to do it but after the prompt for entering a number, nothing happens..

      Comment

      • gpraghuram
        Recognized Expert Top Contributor
        • Mar 2007
        • 1275

        #4
        Hi,
        Try this code
        Code:
        int main()
        {
        	int lnIpChar;
        	printf("Enter the charecter\n");
        	lnIpChar=getchar();
        	printf("%d\n",lnIpChar);
        	if(lnIpChar >= 65 && lnIpChar <= 90)
        	{
        		if(lnIpChar == 90)
        		{
        			lnIpChar = 64;
        		}
        		printf("%c\n",++lnIpChar);
        	}
        	else
        	{
        		printf("%c\n",lnIpChar);
        	}
        
        }
        Thanks
        Raghuram

        Comment

        • svlsr2000
          Recognized Expert New Member
          • Feb 2007
          • 181

          #5
          Originally posted by gpraghuram
          Hi,
          Try this code
          Code:
          int main()
          {
          	int lnIpChar;
          	printf("Enter the charecter\n");
          	lnIpChar=getchar();
          	printf("%d\n",lnIpChar);
          	if(lnIpChar >= 65 && lnIpChar <= 90)
          	{
          		if(lnIpChar == 90)
          		{
          			lnIpChar = 64;
          		}
          		printf("%c\n",++lnIpChar);
          	}
          	else
          	{
          		printf("%c\n",lnIpChar);
          	}
          
          }
          Thanks
          Raghuram
          hi zaacze can you post your code to see where you are getting struck up

          Comment

          • zaacze
            New Member
            • Mar 2007
            • 11

            #6
            hi! the program u've shown is basically the same with what am doing now... the problem is, now after entering a character, nothing happens, it doesn't show anything not unless you would try to run the program agen... that's exactly where i am stuck!...

            Comment

            • gpraghuram
              Recognized Expert Top Contributor
              • Mar 2007
              • 1275

              #7
              Hi,
              I executed it and i am getting the output properly.
              I entered A and then pressed "Enter" key and got the output as B.
              I cant make out why its not happeneing for you
              Thanks
              Raghuram

              Comment

              • zaacze
                New Member
                • Mar 2007
                • 11

                #8
                anyway, thanks a lot for the help...

                Comment

                • Savage
                  Recognized Expert Top Contributor
                  • Feb 2007
                  • 1759

                  #9
                  Originally posted by gpraghuram
                  Hi,
                  Try this code
                  Code:
                  int main()
                  {
                  	int lnIpChar;
                  	printf("Enter the charecter\n");
                  	lnIpChar=getchar();
                  	printf("%d\n",lnIpChar);
                  	if(lnIpChar >= 65 && lnIpChar <= 90)
                  	{
                  		if(lnIpChar == 90)
                  		{
                  			lnIpChar = 64;
                  		}
                  		printf("%c\n",++lnIpChar);
                  	}
                  	else
                  	{
                  		printf("%c\n",lnIpChar);
                  	}
                  
                  }
                  Thanks
                  Raghuram

                  Maybe because your main() is not returning a value.


                  Savage

                  Comment

                  • JosAH
                    Recognized Expert MVP
                    • Mar 2007
                    • 11453

                    #10
                    If you're sure that the parameter is an uppercase letter you can simply define
                    a macro like this:

                    Code:
                    #define NEXT(U) ((U == 'Z')?'A':(U+1))
                    kind regards,

                    Jos

                    Comment

                    Working...