I know I would first declare the input variable as char. But that just reads in the first letter of the word.
How can I print or read each letter of a certain word?
tquiva 7 Junior Poster in Training
Recommended Answers
Jump to PostCharacter array.
Jump to PostIs there any other way of doing it without the use of arrays?
In the context you've mentioned a word is an array of characters. And since you're dealing with an array of characters--i.e. a word as you put it--you must deal with the 'word' as an array.
There …
Jump to PostI created a program like this
#include <stdio.h> main() { /* Declare variables */ char word[] = " "; printf("Enter a word: "); scanf("%s", &word); printf("The word entered is %s\n", word); }
It compiles and runs as I had intended.
Then you're very lucky. Almost any input you use …
Jump to Post
for(i == 0; word[i]; i++)
betterfor (i = 0; word[i] != '\0'; i++)
char word[50] = " ";
betterchar word[50] = { '\0' };
scanf("%s", &word);
betterscanf("%49s", word)
Ponder about why.
All 15 Replies
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
jephthah 1,888 Posting Maven
tquiva 7 Junior Poster in Training
jephthah 1,888 Posting Maven
jephthah 1,888 Posting Maven
tquiva 7 Junior Poster in Training
hkdani 39 Posting Pro in Training
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
tquiva 7 Junior Poster in Training
jephthah 1,888 Posting Maven
hkdani 39 Posting Pro in Training
tquiva 7 Junior Poster in Training
tquiva 7 Junior Poster in Training
Aia 1,977 Nearly a Posting Maven
hkdani 39 Posting Pro in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.