Home > other >  Null output dealing with file IO in C#
Null output dealing with file IO in C#

Time:03-28

        private async void btnClickThis_Click(object sender, EventArgs e)
    {
        //using example code from: https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.filedialog?view=windowsdesktop-6.0
        //to open a file dialog box and allow selection

        //variable declaration by section
        //file processing
        var fileContent = string.Empty;
        var filePath = string.Empty;
        //counting vowels and storing the word
        int vowelMax = 0;
        int vowelCount = 0;
        String maxVowels = "";
        //finding length and storing longest word
        int length = 0;
        int lengthMax = 0;
        String maxLength = "";
        //for storing first and last words alphabetically
        String first = "";
        String last = "";

        using (OpenFileDialog openFileDialog = new OpenFileDialog())
        {
            openFileDialog.InitialDirectory = "c:\\";
            openFileDialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
            openFileDialog.FilterIndex = 2;
            openFileDialog.RestoreDirectory = true;

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                //Get the path of specified file
                filePath = openFileDialog.FileName;

                //Read the contents of the file into a stream
                var fileStream = openFileDialog.OpenFile();
                using StreamWriter file = new("Stats.txt", append: true);
                using (StreamReader reader = new StreamReader(fileStream))
                {

                    do
                    {
                        //try catch in case file is null to begin with
                        try
                        {
                            //read one line at a time, converting it to lower case to start
                            fileContent = reader?.ReadLine()?.ToLower();
                            //split line into words, removing empty entries and separating by spaces
                            var words = fileContent?.Split(' ', StringSplitOptions.RemoveEmptyEntries);
                            if (words != null)
                            {
                                foreach (var word in words)
                                {
                                    //if the string is null, immediately store word
                                    //if word < first, store word as first
                                    if (first == null || String.Compare(word, first) < 0)
                                    {
                                        first = word;
                                    }
                                    //if the string is null, immediately store word
                                    //if word > last, store word as last
                                    else if (last == null || String.Compare(word, last) > 0)
                                    {
                                        last = word;
                                    }

                                    //find length of current word
                                    length = word.Length;
                                    //if len is greater than current max len, store new max len word
                                    if (length > lengthMax)
                                    {
                                        maxLength = word;
                                    }
                                    //iterate over each letter to check for vowels and total them up
                                    for (int i = 0; i < length; i  )
                                    {
                                        if (word[i] == 'a' || word[i] == 'e' || word[i] == 'i' || word[i] == 'o' || word[i] == 'u')
                                        {
                                            vowelCount  ;
                                        }
                                    }
                                    //if vowelCount is greater than max, store word as new max
                                    if (vowelCount > vowelMax)
                                    {
                                        maxVowels = word;
                                    }
                                    await file.WriteLineAsync(word);
                                }
                            }
                        } catch (IOException error)
                        {
                            Console.WriteLine("IOException source: {0}", error.Source);
                        }
                    } while (fileContent != "");
                    //append file stats after processing is complete
                    await file.WriteLineAsync("First word(Alphabetically): "   first);
                    await file.WriteLineAsync("Last word(Alphabetically): "   last);
                    await file.WriteLineAsync("Longest word: "   maxLength);
                    await file.WriteLineAsync("Word with the most vowels: "   maxVowels);
                }
            }
        }
        MessageBox.Show(fileContent, "File Content at path: "   filePath, MessageBoxButtons.OK);
    }

I have looked at everything for far too long right now, and cannot see anything wrong with this. I'm taking a file that 100% has data(And using a try catch block in case it does not have any data), and processing its information, then spitting it back into a text file. I'm not getting any output, and I feel like(due to how many times I had to use ? to get rid of null file warnings) that my error exists in the fileContent = reader?.ReadLine()?.ToLower(); line or the var words = fileContent?.Split(' ', StringSplitOptions.RemoveEmptyEntries); line. Any and all help would be appreciated

EDIT: Fixed my file IO Issue by changing reader?.readLine()?.ToLower(); to reader.readToEnd() and separating off fileContent = fileContent.toLower().

Now having the issue of multiple iterations over the same file. When putting in my test data (of which I'm just using a list of the original pokemon in all caps), I'm getting an output of every single word it iterates over(I'm not sure of where I'm explicitly stating to output each word in words) and I'm getting multiple outputs of the same things.

Here is my updated code: ` private async void btnClickThis_Click(object sender, EventArgs e) { //using example code from: https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.filedialog?view=windowsdesktop-6.0 //to open a file dialog box and allow selection

        //variable declaration by section
        //file processing
        var fileContent = string.Empty;
        var filePath = string.Empty;
        //counting vowels and storing the word
        int vowelMax = 0;
        int vowelCount = 0;
        String maxVowels = "";
        //finding length and storing longest word
        int length = 0;
        int lengthMax = 0;
        //for storing first and last words alphabetically
        String first = "";
        String last = "";

        using (OpenFileDialog openFileDialog = new OpenFileDialog())
        {
            openFileDialog.InitialDirectory = "c:\\";
            openFileDialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
            openFileDialog.FilterIndex = 2;
            openFileDialog.RestoreDirectory = true;

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                //Get the path of specified file
                filePath = openFileDialog.FileName;

                //Read the contents of the file into a stream
                var fileStream = openFileDialog.OpenFile();
                using StreamWriter file = new("Stats.txt", append: true);
                using StreamWriter test = new("testoutput.txt", append: true);
                using (StreamReader reader = new StreamReader(fileStream))
                {

                    do
                    {
                        //try catch in case file is null to begin with
                        try
                        {
                            //read the file, converting it to lower case to start
                            fileContent = reader.ReadToEnd();
                            fileContent = fileContent.ToLower();
                            //split file into words, removing empty entries and separating by spaces and new lines
                            var words = fileContent.Split(' ', '\n');
                            await test.WriteLineAsync("words: "   words   "\n");
                            //get longest word of file
                            var maxLength = words.OrderByDescending(n => n.Length).First();
                            await file.WriteLineAsync("Longest word: "   maxLength   "\n");
                            if (words != null)
                            {
                                foreach (var word in words)
                                {
                                    await test.WriteLineAsync("current word: "   word   "\n");
                                    
                                    //if word < first, store word as first
                                    if (String.Compare(word, first) < 0)
                                    {
                                        first = word;
                                    }
                                    
                                    //if word > last, store word as last
                                    else if (String.Compare(word, last) > 0)
                                    {
                                        last = word;
                                    }

                                    //find length of current word
                                    length = word.Length;
                                    //if len is greater than current max len, store new max len word
                                    if (length > lengthMax)
                                    {
                                        maxLength = word;
                                    }
                                    //iterate over each letter to check for vowels and total them up
                                    vowelCount = 0;
                                    for (int i = 0; i < length; i  )
                                    {
                                        
                                        if (word[i] == 'a' || word[i] == 'e' || word[i] == 'i' || word[i] == 'o' || word[i] == 'u')
                                        {
                                            vowelCount  ;
                                            await test.WriteLineAsync(word[i]   "\n");
                                            await test.WriteLineAsync(vowelCount   "\n");
                                            //if vowelCount is greater than max, store word as new max
                                            if (vowelCount > vowelMax)
                                            {
                                                vowelMax = vowelCount;
                                                maxVowels = word;
                                            }
                                        }
                                    }
                                    
                                    //await file.WriteLineAsync(word);
                                }
                            }
                        } catch (IOException error)
                        {
                            Console.WriteLine("IOException source: {0}", error.Source);
                        }
                    } while (fileContent != "");
                    //append file stats after processing is complete
                    await file.WriteLineAsync("First word(Alphabetically): "   first   "\n");
                    await file.WriteLineAsync("Last word(Alphabetically): "   last   "\n");
                    
                    await file.WriteLineAsync("Word with the most vowels: "   maxVowels   "\n");
                }
            }
        }
        MessageBox.Show(fileContent, "File Content at path: "   filePath, MessageBoxButtons.OK);
    }`

and here is my output to file, which should be a formatted text file showing no caps(check), the first and last words alphabetically(last is working, first is not), the longest word(check), and the word with the most vowels(check).

bulbasaur
ivysaur
venusaur
charmander
charmeleon
charizard
squirtle
wartortle
blastoise
caterpie
metapod
butterfree
weedle
kakuna
beedrill
pidget
pidgeotto
pidgeot
rattata
raticate
spearow
fearow
ekans
arbok
pikachu
raichu
sandshrew
sandslash
nidoran
nidorina
nidoqueen
nidoran
nidorino
nidoking
clefairy
clefable
vulpix
ninetales
jigglypuff
wigglytuff
zubat
golbat
oddish
gloom
vileplume
paras
parasect
venonat
venomoth
diglett
dugtrio
meowth
persian
psyduck
golduck
mankey
primeape
growlithe
arcanine
poliwag
poliwhirl
poliwrath
abra
kadabra
alakazam
machop
machoke
machamp
bellsprout
weepinbell
victreebel
tentacool
tentacruel
geodude
graveler
golem
ponyta
rapidash
slowpoke
slowbro
magnemite
magneton
farfetch'd
doduo
dodrio
seel
dewgong
grimer
muk
shellder
cloyster
gastly
haunter
gengar
onix
drowzee
hypno
krabby
kingler
voltorb
electrode
exeggcute
exeggutor
cubone
marowak
hitmonlee
hitmonchan
lickitung
koffing
weezing
rhyhorn
rhydon
chansey
tangela
kangaskhan
horsea
seadra
goldeen
seaking
staryu
starmie
mrmime
scyther
jynx
electabuzz
magmar
pinsir
tauros
magikarp
gyarados
lapras
ditto
eevee
vaporeon
jolteon
flareon
porygon
omanyte
omastar
kabuto
kabutops
aerodactyl
snorlax
articuno
zapdos
moltres
dratini
dragonair
dragonite
mewtwo
mew
First word(Alphabetically): 

Last word(Alphabetically): bulbasaur
ivysaur
venusaur
charmander
charmeleon
charizard
squirtle
wartortle
blastoise
caterpie
metapod
butterfree
weedle
kakuna
beedrill
pidget
pidgeotto
pidgeot
rattata
raticate
spearow
fearow
ekans
arbok
pikachu
raichu
sandshrew
sandslash
nidoran
nidorina
nidoqueen
nidoran
nidorino
nidoking
clefairy
clefable
vulpix
ninetales
jigglypuff
wigglytuff
zubat
golbat
oddish
gloom
vileplume
paras
parasect
venonat
venomoth
diglett
dugtrio
meowth
persian
psyduck
golduck
mankey
primeape
growlithe
arcanine
poliwag
poliwhirl
poliwrath
abra
kadabra
alakazam
machop
machoke
machamp
bellsprout
weepinbell
victreebel
tentacool
tentacruel
geodude
graveler
golem
ponyta
rapidash
slowpoke
slowbro
magnemite
magneton
farfetch'd
doduo
dodrio
seel
dewgong
grimer
muk
shellder
cloyster
gastly
haunter
gengar
onix
drowzee
hypno
krabby
kingler
voltorb
electrode
exeggcute
exeggutor
cubone
marowak
hitmonlee
hitmonchan
lickitung
koffing
weezing
rhyhorn
rhydon
chansey
tangela
kangaskhan
horsea
seadra
goldeen
seaking
staryu
starmie
mrmime
scyther
jynx
electabuzz
magmar
pinsir
tauros
magikarp
gyarados
lapras
ditto
eevee
vaporeon
jolteon
flareon
porygon
omanyte
omastar
kabuto
kabutops
aerodactyl
snorlax
articuno
zapdos
moltres
dratini
dragonair
dragonite
mewtwo
mew

Longest word: bulbasaur
ivysaur
venusaur
charmander
charmeleon
charizard
squirtle
wartortle
blastoise
caterpie
metapod
butterfree
weedle
kakuna
beedrill
pidget
pidgeotto
pidgeot
rattata
raticate
spearow
fearow
ekans
arbok
pikachu
raichu
sandshrew
sandslash
nidoran
nidorina
nidoqueen
nidoran
nidorino
nidoking
clefairy
clefable
vulpix
ninetales
jigglypuff
wigglytuff
zubat
golbat
oddish
gloom
vileplume
paras
parasect
venonat
venomoth
diglett
dugtrio
meowth
persian
psyduck
golduck
mankey
primeape
growlithe
arcanine
poliwag
poliwhirl
poliwrath
abra
kadabra
alakazam
machop
machoke
machamp
bellsprout
weepinbell
victreebel
tentacool
tentacruel
geodude
graveler
golem
ponyta
rapidash
slowpoke
slowbro
magnemite
magneton
farfetch'd
doduo
dodrio
seel
dewgong
grimer
muk
shellder
cloyster
gastly
haunter
gengar
onix
drowzee
hypno
krabby
kingler
voltorb
electrode
exeggcute
exeggutor
cubone
marowak
hitmonlee
hitmonchan
lickitung
koffing
weezing
rhyhorn
rhydon
chansey
tangela
kangaskhan
horsea
seadra
goldeen
seaking
staryu
starmie
mrmime
scyther
jynx
electabuzz
magmar
pinsir
tauros
magikarp
gyarados
lapras
ditto
eevee
vaporeon
jolteon
flareon
porygon
omanyte
omastar
kabuto
kabutops
aerodactyl
snorlax
articuno
zapdos
moltres
dratini
dragonair
dragonite
mewtwo
mew

Word with the most vowels: bulbasaur
ivysaur
venusaur
charmander
charmeleon
charizard
squirtle
wartortle
blastoise
caterpie
metapod
butterfree
weedle
kakuna
beedrill
pidget
pidgeotto
pidgeot
rattata
raticate
spearow
fearow
ekans
arbok
pikachu
raichu
sandshrew
sandslash
nidoran
nidorina
nidoqueen
nidoran
nidorino
nidoking
clefairy
clefable
vulpix
ninetales
jigglypuff
wigglytuff
zubat
golbat
oddish
gloom
vileplume
paras
parasect
venonat
venomoth
diglett
dugtrio
meowth
persian
psyduck
golduck
mankey
primeape
growlithe
arcanine
poliwag
poliwhirl
poliwrath
abra
kadabra
alakazam
machop
machoke
machamp
bellsprout
weepinbell
victreebel
tentacool
tentacruel
geodude
graveler
golem
ponyta
rapidash
slowpoke
slowbro
magnemite
magneton
farfetch'd
doduo
dodrio
seel
dewgong
grimer
muk
shellder
cloyster
gastly
haunter
gengar
onix
drowzee
hypno
krabby
kingler
voltorb
electrode
exeggcute
exeggutor
cubone
marowak
hitmonlee
hitmonchan
lickitung
koffing
weezing
rhyhorn
rhydon
chansey
tangela
kangaskhan
horsea
seadra
goldeen
seaking
staryu
starmie
mrmime
scyther
jynx
electabuzz
magmar
pinsir
tauros
magikarp
gyarados
lapras
ditto
eevee
vaporeon
jolteon
flareon
porygon
omanyte
omastar
kabuto
kabutops
aerodactyl
snorlax
articuno
zapdos
moltres
dratini
dragonair
dragonite
mewtwo
mew

bulbasaur
ivysaur
venusaur
charmander
charmeleon
charizard
squirtle
wartortle
blastoise
caterpie
metapod
butterfree
weedle
kakuna
beedrill
pidget
pidgeotto
pidgeot
rattata
raticate
spearow
fearow
ekans
arbok
pikachu
raichu
sandshrew
sandslash
nidoran
nidorina
nidoqueen
nidoran
nidorino
nidoking
clefairy
clefable
vulpix
ninetales
jigglypuff
wigglytuff
zubat
golbat
oddish
gloom
vileplume
paras
parasect
venonat
venomoth
diglett
dugtrio
meowth
persian
psyduck
golduck
mankey
primeape
growlithe
arcanine
poliwag
poliwhirl
poliwrath
abra
kadabra
alakazam
machop
machoke
machamp
bellsprout
weepinbell
victreebel
tentacool
tentacruel
geodude
graveler
golem
ponyta
rapidash
slowpoke
slowbro
magnemite
magneton
farfetch'd
doduo
dodrio
seel
dewgong
grimer
muk
shellder
cloyster
gastly
haunter
gengar
onix
drowzee
hypno
krabby
kingler
voltorb
electrode
exeggcute
exeggutor
cubone
marowak
hitmonlee
hitmonchan
lickitung
koffing
weezing
rhyhorn
rhydon
chansey
tangela
kangaskhan
horsea
seadra
goldeen
seaking
staryu
starmie
mrmime
scyther
jynx
electabuzz
magmar
pinsir
tauros
magikarp
gyarados
lapras
ditto
eevee
vaporeon
jolteon
flareon
porygon
omanyte
omastar
kabuto
kabutops
aerodactyl
snorlax
articuno
zapdos
moltres
dratini
dragonair
dragonite
mewtwo
mew
First word(Alphabetically): 

Last word(Alphabetically): bulbasaur
ivysaur
venusaur
charmander
charmeleon
charizard
squirtle
wartortle
blastoise
caterpie
metapod
butterfree
weedle
kakuna
beedrill
pidget
pidgeotto
pidgeot
rattata
raticate
spearow
fearow
ekans
arbok
pikachu
raichu
sandshrew
sandslash
nidoran
nidorina
nidoqueen
nidoran
nidorino
nidoking
clefairy
clefable
vulpix
ninetales
jigglypuff
wigglytuff
zubat
golbat
oddish
gloom
vileplume
paras
parasect
venonat
venomoth
diglett
dugtrio
meowth
persian
psyduck
golduck
mankey
primeape
growlithe
arcanine
poliwag
poliwhirl
poliwrath
abra
kadabra
alakazam
machop
machoke
machamp
bellsprout
weepinbell
victreebel
tentacool
tentacruel
geodude
graveler
golem
ponyta
rapidash
slowpoke
slowbro
magnemite
magneton
farfetch'd
doduo
dodrio
seel
dewgong
grimer
muk
shellder
cloyster
gastly
haunter
gengar
onix
drowzee
hypno
krabby
kingler
voltorb
electrode
exeggcute
exeggutor
cubone
marowak
hitmonlee
hitmonchan
lickitung
koffing
weezing
rhyhorn
rhydon
chansey
tangela
kangaskhan
horsea
seadra
goldeen
seaking
staryu
starmie
mrmime
scyther
jynx
electabuzz
magmar
pinsir
tauros
magikarp
gyarados
lapras
ditto
eevee
vaporeon
jolteon
flareon
porygon
omanyte
omastar
kabuto
kabutops
aerodactyl
snorlax
articuno
zapdos
moltres
dratini
dragonair
dragonite
mewtwo
mew

Longest word: bulbasaur
ivysaur
venusaur
charmander
charmeleon
charizard
squirtle
wartortle
blastoise
caterpie
metapod
butterfree
weedle
kakuna
beedrill
pidget
pidgeotto
pidgeot
rattata
raticate
spearow
fearow
ekans
arbok
pikachu
raichu
sandshrew
sandslash
nidoran
nidorina
nidoqueen
nidoran
nidorino
nidoking
clefairy
clefable
vulpix
ninetales
jigglypuff
wigglytuff
zubat
golbat
oddish
gloom
vileplume
paras
parasect
venonat
venomoth
diglett
dugtrio
meowth
persian
psyduck
golduck
mankey
primeape
growlithe
arcanine
poliwag
poliwhirl
poliwrath
abra
kadabra
alakazam
machop
machoke
machamp
bellsprout
weepinbell
victreebel
tentacool
tentacruel
geodude
graveler
golem
ponyta
rapidash
slowpoke
slowbro
magnemite
magneton
farfetch'd
doduo
dodrio
seel
dewgong
grimer
muk
shellder
cloyster
gastly
haunter
gengar
onix
drowzee
hypno
krabby
kingler
voltorb
electrode
exeggcute
exeggutor
cubone
marowak
hitmonlee
hitmonchan
lickitung
koffing
weezing
rhyhorn
rhydon
chansey
tangela
kangaskhan
horsea
seadra
goldeen
seaking
staryu
starmie
mrmime
scyther
jynx
electabuzz
magmar
pinsir
tauros
magikarp
gyarados
lapras
ditto
eevee
vaporeon
jolteon
flareon
porygon
omanyte
omastar
kabuto
kabutops
aerodactyl
snorlax
articuno
zapdos
moltres
dratini
dragonair
dragonite
mewtwo
mew

Word with the most vowels: bulbasaur
ivysaur
venusaur
charmander
charmeleon
charizard
squirtle
wartortle
blastoise
caterpie
metapod
butterfree
weedle
kakuna
beedrill
pidget
pidgeotto
pidgeot
rattata
raticate
spearow
fearow
ekans
arbok
pikachu
raichu
sandshrew
sandslash
nidoran
nidorina
nidoqueen
nidoran
nidorino
nidoking
clefairy
clefable
vulpix
ninetales
jigglypuff
wigglytuff
zubat
golbat
oddish
gloom
vileplume
paras
parasect
venonat
venomoth
diglett
dugtrio
meowth
persian
psyduck
golduck
mankey
primeape
growlithe
arcanine
poliwag
poliwhirl
poliwrath
abra
kadabra
alakazam
machop
machoke
machamp
bellsprout
weepinbell
victreebel
tentacool
tentacruel
geodude
graveler
golem
ponyta
rapidash
slowpoke
slowbro
magnemite
magneton
farfetch'd
doduo
dodrio
seel
dewgong
grimer
muk
shellder
cloyster
gastly
haunter
gengar
onix
drowzee
hypno
krabby
kingler
voltorb
electrode
exeggcute
exeggutor
cubone
marowak
hitmonlee
hitmonchan
lickitung
koffing
weezing
rhyhorn
rhydon
chansey
tangela
kangaskhan
horsea
seadra
goldeen
seaking
staryu
starmie
mrmime
scyther
jynx
electabuzz
magmar
pinsir
tauros
magikarp
gyarados
lapras
ditto
eevee
vaporeon
jolteon
flareon
porygon
omanyte
omastar
kabuto
kabutops
aerodactyl
snorlax
articuno
zapdos
moltres
dratini
dragonair
dragonite
mewtwo
mew

bulbasaur
ivysaur
venusaur
charmander
charmeleon
charizard
squirtle
wartortle
blastoise
caterpie
metapod
butterfree
weedle
kakuna
beedrill
pidget
pidgeotto
pidgeot
rattata
raticate
spearow
fearow
ekans
arbok
pikachu
raichu
sandshrew
sandslash
nidoran
nidorina
nidoqueen
nidoran
nidorino
nidoking
clefairy
clefable
vulpix
ninetales
jigglypuff
wigglytuff
zubat
golbat
oddish
gloom
vileplume
paras
parasect
venonat
venomoth
diglett
dugtrio
meowth
persian
psyduck
golduck
mankey
primeape
growlithe
arcanine
poliwag
poliwhirl
poliwrath
abra
kadabra
alakazam
machop
machoke
machamp
bellsprout
weepinbell
victreebel
tentacool
tentacruel
geodude
graveler
golem
ponyta
rapidash
slowpoke
slowbro
magnemite
magneton
farfetch'd
doduo
dodrio
seel
dewgong
grimer
muk
shellder
cloyster
gastly
haunter
gengar
onix
drowzee
hypno
krabby
kingler
voltorb
electrode
exeggcute
exeggutor
cubone
marowak
hitmonlee
hitmonchan
lickitung
koffing
weezing
rhyhorn
rhydon
chansey
tangela
kangaskhan
horsea
seadra
goldeen
seaking
staryu
starmie
mrmime
scyther
jynx
electabuzz
magmar
pinsir
tauros
magikarp
gyarados
lapras
ditto
eevee
vaporeon
jolteon
flareon
porygon
omanyte
omastar
kabuto
kabutops
aerodactyl
snorlax
articuno
zapdos
moltres
dratini
dragonair
dragonite
mewtwo
mew
First word(Alphabetically): 



Longest word: charmander

bulbasaur

ivysaur

venusaur

charmander

charmeleon

charizard

squirtle

wartortle

blastoise

caterpie

metapod

butterfree

weedle

kakuna

beedrill

pidget

pidgeotto

pidgeot

rattata

raticate

spearow

fearow

ekans

arbok

pikachu

raichu

sandshrew

sandslash

nidoran

nidorina

nidoqueen

nidoran

nidorino

nidoking

clefairy

clefable

vulpix

ninetales

jigglypuff

wigglytuff

zubat

golbat

oddish

gloom

vileplume

paras

parasect

venonat

venomoth

diglett

dugtrio

meowth

persian

psyduck

golduck

mankey

primeape

growlithe

arcanine

poliwag

poliwhirl

poliwrath

abra

kadabra

alakazam

machop

machoke

machamp

bellsprout

weepinbell

victreebel

tentacool

tentacruel

geodude

graveler

golem

ponyta

rapidash

slowpoke

slowbro

magnemite

magneton

farfetch'd

doduo

dodrio

seel

dewgong

grimer

muk

shellder

cloyster

gastly

haunter

gengar

onix

drowzee

hypno

krabby

kingler

voltorb

electrode

exeggcute

exeggutor

cubone

marowak

hitmonlee

hitmonchan

lickitung

koffing

weezing

rhyhorn

rhydon

chansey

tangela

kangaskhan

horsea

seadra

goldeen

seaking

staryu

starmie

mrmime

scyther

jynx

electabuzz

magmar

pinsir

tauros

magikarp

gyarados

lapras

ditto

eevee

vaporeon

jolteon

flareon

porygon

omanyte

omastar

kabuto

kabutops

aerodactyl

snorlax

articuno

zapdos

moltres

dratini

dragonair

dragonite

mewtwo

mew
Longest word: 


First word(Alphabetically): 

Last word(Alphabetically): zubat

Word with the most vowels: 

Longest word: charmander

Longest word: 

First word(Alphabetically): 

Last word(Alphabetically): zubat

Word with the most vowels: 

Longest word: charmander

Longest word: 

First word(Alphabetically): 

Last word(Alphabetically): zubat

Word with the most vowels: 

Longest word: charmander

Longest word: 

First word(Alphabetically): 

Last word(Alphabetically): zubat

Word with the most vowels: 

Longest word: charmander

Longest word: 

First word(Alphabetically): 

Last word(Alphabetically): zubat

Word with the most vowels: mew

Longest word: charmander

Longest word: 

First word(Alphabetically): 

Last word(Alphabetically): zubat

Word with the most vowels: mew

Longest word: charmander

Longest word: 

First word(Alphabetically): 

Last word(Alphabetically): zubat

Word with the most vowels: mew

Longest word: charmander

Longest word: 

First word(Alphabetically): 

Last word(Alphabetically): zubat

Word with the most vowels: nidoqueen

CodePudding user response:

here you try to find first (min ) word.

             string first = "";
             ....
             if (String.Compare(word, first) < 0)
             {
                  first = word;
             }

but "" comes before all strings. So that compare is always false. Do

             string first = "";
             ....
             if (String == "" || String.Compare(word, first) < 0)
             {
                  first = word;
             }
  • Related