Thread: Incrementing letters problem

  1. #1
    Registered User
    Join Date
    Dec 2015
    Posts
    7

    Incrementing letters problem

    I'm trying to make a program that takes the input of a letter from b-z and increments its, but the only thing I get from the program is the same letter printed again.

    Code:
    #include <stdio.h>
    
    
    int main()
    {
    char firstLetter;
    char secondLetter;
    
    
    
    
    printf("Put in a letter from b - z in the alphabet: ");
    scanf("%c", firstLetter);
    printf("%c", firstLetter);
    secondLetter= firstLetter + 1;
    printf("%c", secondLetter);
    
    
    
    
    
    
    return 0; 
    }

  2. #2
    Registered User
    Join Date
    Sep 2014
    Posts
    364
    scanf needs a 'char *' as second argument, not a 'char'.
    Other have classes, we are class

  3. #3
    Registered User
    Join Date
    Dec 2015
    Posts
    7
    Code:
    scanf("%c", firstLetter *);
    or am I missing something?
    Thank you for the reply

  4. #4
    Registered User
    Join Date
    Sep 2014
    Posts
    364
    'char *' means a pointer to a 'char'. This is the address of a memory where a char is stored.
    Your line should look like
    Code:
    scanf("%c", &firstLetter);
    The '&' is the 'address of' operator.
    The line says exactly:
    scan formated for one character and store it at the memory address of firstLetter.
    Other have classes, we are class

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 09-11-2013, 11:12 PM
  2. Replies: 1
    Last Post: 01-24-2012, 11:28 PM
  3. problem incrementing 2D array
    By spence21989 in forum C Programming
    Replies: 19
    Last Post: 02-01-2011, 09:07 PM
  4. strcmp, a problem with capital letters
    By RichardH in forum C Programming
    Replies: 11
    Last Post: 04-23-2007, 08:49 AM
  5. problem with letters
    By librab103 in forum C Programming
    Replies: 3
    Last Post: 08-08-2003, 01:54 PM

Tags for this Thread