Thread: Better way of declaring char?

  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    1

    Better way of declaring char?

    Hi. I came across this piece of code below and was thinking, isn't there a better way of declaring a char for a single character? I also saw the same thing done here

    Code:
      char letter = ' ';
      printf("enter letter\n");
      scanf("%c",&letter);
      printf("print letter %c\n",letter);

    I tried, char letter[0], but it didn't work. I thought it would declare an array of char with 1 element.

    If I entered, char letter; would that be a char of 1 ?

    Thanks

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    char letter;
    is fine, since having no brackets would imply that it is no array and an array, by definition, is a collection of n (where n > 1) contiguous elements of the type you declare it to be.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ ini file reader problems
    By guitarist809 in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2008, 06:02 AM
  2. Sorting Linked Lists
    By DKING89 in forum C Programming
    Replies: 6
    Last Post: 04-09-2008, 07:36 AM
  3. How do i un-SHA1 hash something..
    By willc0de4food in forum C Programming
    Replies: 4
    Last Post: 09-14-2005, 05:59 AM
  4. Passing structures... I can't get it right.
    By j0hnb in forum C Programming
    Replies: 6
    Last Post: 01-26-2003, 11:55 AM
  5. String sorthing, file opening and saving.
    By j0hnb in forum C Programming
    Replies: 9
    Last Post: 01-23-2003, 01:18 AM

Tags for this Thread