Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Computer science assignment. (strings)

  1. Nov 1, 2006 #1
    i need a make a program that prompts the user to enter a string, and for it to identify the uppercase characters and replace each uppercase char with the corresponding lowercase character. it also needs to count the character

    here's what i have so far:

    Code (Text):
    #include<stdio.h>
    #include<string.h>
    main()
    {

    char
            letter[20];
         
    int uppercount,i;

        uppercount=0;
           
        printf("Please enter characters:\n");
        gets(letter);

        if(letter[i]>= 'A' && letter[i] <='Z')      
        uppercount++;
        {
            letter[i] = letter[i] - 'A'+ 'a';
       
     }
        printf("%c\n", letter);
           printf("The number of uppercase letters entered: %d", uppercount);
    }

     
    doesn't seem to work as i would like.. what changes should i make?
     
  2. jcsd
  3. Nov 1, 2006 #2
    Initialize your variables and be aware the the letter in the printf will attempt to print out the address of the array as a character (you need to dereference your array by adding a and put it inside a loop since %c will print (I believe) out one character at a time). You also need some kind of loop to count the uppercase letters.
     
    Last edited: Nov 1, 2006
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook