Thread: convert from upper to lower

  1. #16
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    If you are using an integrated editor for your compiler, it should have a "debugger" option that will allow you to step through your code, one line at a time, and at the same time, watch several variable values to see how they're changing, etc.

    printing out a quick variable is a very valuable debugging aid, as well. Even if you're not running the program in "debug" mode.

  2. #17
    Registered User
    Join Date
    Nov 2012
    Posts
    24
    Quote Originally Posted by iMalc View Post
    No, don't do that. Why did you change it from the perfectly descriptive 'A' and 'Z' etc to 65 and 90?
    You'd best change those back.

    Also, that magic number 32 is bad as well. You could instead return ch + 'A' - 'a'; for to_upper, for example.
    i changed it then i changed it to 'A','Z'
    thank you

  3. #18
    Registered User
    Join Date
    Nov 2012
    Posts
    24
    Quote Originally Posted by Adak View Post
    123456 - The input

    My thinking goes like this:

    #1.
    for every digit in the set of digits, print it, then print a space

    #2.
    for(every digit in the set of digits)
    ....print the digit and a space

    #3.
    for(i equals first digit, i is less than or equal to 6, increment i)
    ....printf(the digit and 1 space)

    Ready to code up the loop.

    It's odd to take it through these steps, because with practice, you just say "got it", and code it. But the process REALLY comes into play with any problem where you don't have an answer.

    Failing anything better, start with how YOU would do it, and take that logic step by step, to your program.
    i'm going to do that practice and practice
    i need more problems that let me learn

    Working
    Code:
    #include<stdio.h>
    #include<string.h>
    int main()
    {
    
        char arr[100];
        int i=0;
        fgets(arr,100,stdin);
        int x=strlen(arr);
        for(i=0;i<x;i++){
    
            printf(" %c",arr[i]);
    
        }
    
        return 0;
    
    }

    Working
    Code:
    #include<stdio.h>
    #include<string.h>
    int main()
    {
    
        char arr[100];
        int i=0;
        fgets(arr,100,stdin);
    
        while(i<strlen(arr)){
    
            printf(" %c",arr[i]);
            i++;
        }
    
        return 0;
    }
    Not Working i used debugger step by step it go ahead to return 0 Why?

    Code:
    #include<stdio.h>
    #include<string.h>
    int main()
    {
    
        char arr[100];
        int i;
        fgets(arr,100,stdin);
    
        for(i=0;i!='\0';i++){
    
            printf(" %c",arr[i]);
    
        }
    
        return 0;
    }
    Not Working i used debugger step by step it go ahead to return 0
    Why?
    loop till find the Null terminator ?

    Code:
    #include<stdio.h>
    #include<string.h>
    int main()
    {
    
        char arr[100];
        int i=0;
        fgets(arr,100,stdin);
    
        while(i!='\0'){
    
            printf(" %c",arr[i]);
            i++;
        }
    
        return 0;
    }
    Not Working i used debugger step by step it go ahead to return 0

    Code:
    #include<stdio.h>
    #include<string.h>
    int main()
    {
    
        char arr[100];
        int i=0;
        fgets(arr,100,stdin);
    
        while(arr){
            if(i!='\0'){
            printf(" %c",arr[i]);
            i++;}
            else
                return 0;
        }
    
        return 0;
    }
    in the first,second Code i used strlen() that will count the Null terminator
    i mean it is the same idea with the other 3 code
    so what is the problem
    Last edited by tost; 02-04-2013 at 11:17 PM.

  4. #19
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    This:
    Code:
     for(i=0;i!='\0';i++){
    is incorrect. You're telling the for loop to quit if i does not equal '\0'. But i is an int, and i =0 is the equivalent of i='\0', so the test evaluates to true, causing the loop to quit , before it loops.

    Add this line inside the for loop. See how many times it prints the value of i:

    Code:
    printf("i equals: %d\n",i);
    That's one of the beauties of programming - you can test your own ideas out.
    Last edited by Adak; 02-05-2013 at 02:00 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. String upper-lower case
    By icor15 in forum C Programming
    Replies: 1
    Last Post: 11-26-2012, 03:00 AM
  2. to lower or to upper that is the question!
    By verbity in forum C++ Programming
    Replies: 20
    Last Post: 04-25-2007, 06:42 PM
  3. Lower to Upper
    By Krush in forum C Programming
    Replies: 13
    Last Post: 11-19-2002, 10:14 PM
  4. string converting upper/lower
    By jlamn in forum C Programming
    Replies: 9
    Last Post: 09-24-2002, 06:01 PM
  5. lower to upper
    By Unregistered in forum C Programming
    Replies: 12
    Last Post: 07-29-2002, 07:50 PM