Thread: char arrays

  1. #1
    Registered User
    Join Date
    Dec 2009

    char arrays

    how can i get my programme to read the first character eg, if i have a programme that asks the user to input a word, then reads the word and checks if the first chacter is a vovel

    #include <stdlib.h>
    #include <stdio.h>
    int main (void)

    char a,e,i,o,u, word[50];
    char letter;
    printf("input a word: ");
    scanf("%s", &word);

    letter = word[0];

    system ("pause");
    return 0;

    can you tell me where the mistake is?

  2. #2
    Registered User
    Join Date
    Jan 2005
    You're using the wrong format specifier to output the character. %s is for strings.

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Rishon LeZion, Israel
    #include <stdio.h>
    this header is for C IO routines like printf scanf

    cin >>
    and these are C++ routines which require <iostream> header

    void main() is not standard - see FAQ

    instead of C-strings better to use std::string
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    David J. Wheeler

  4. #4
    Join Date
    Oct 2007
    Inside my computer
    Be careful when reading string with scanf; it's unsafe by default. Scanf woes - cpwiki
    And be sure to read stickies! << !! Posting Code? Read this First !! >>
    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. Obtaining source & destination IP,details of ICMP Header & each of field of it ???
    By cromologic in forum Networking/Device Communication
    Replies: 1
    Last Post: 04-29-2006, 02:49 PM
  2. Half-life SDK, where are the constants?
    By bennyandthejets in forum Game Programming
    Replies: 29
    Last Post: 08-25-2003, 11:58 AM
  3. comparing fields in a text file
    By darfader in forum C Programming
    Replies: 9
    Last Post: 08-22-2003, 08:21 AM
  4. String sorthing, file opening and saving.
    By j0hnb in forum C Programming
    Replies: 9
    Last Post: 01-23-2003, 01:18 AM