-
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];
printf("%s\n",letter);
system ("pause");
return 0;
}
can you tell me where the mistake is?
-
You're using the wrong format specifier to output the character. %s is for strings.
-
#include <stdio.h>
this header is for C IO routines like printf scanf
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
-
Be careful when reading string with scanf; it's unsafe by default. SourceForge.net: Scanf woes - cpwiki
And be sure to read stickies! http://cboard.cprogramming.com/cplus...ead-first.html