+1 ileana jackson · December 18, 2015
I am writing a vowel count program and it counts the vowels perfectly until it gets to 'u'. I keep getting a junk number. Does anyone know how to get the number of u's?

Post a Reply


Oldest  Newest  Rating
0 Linguist Llama · December 29, 2015
Sure, if you only consider "32-bit" compilers (whatever that means, more on that later), and you don't care about portability (or efficiency), you won't mind using a sign bit when you encode sizes, so you can encode negative sizes for some reason... Neat!

Oh, but it's so easy to avoid writing non-portable and non-optimal code in this case. All you have to do is wrote "size_t" instead of "int"... What's so hard about that?

What's hard seems to be admitting that you're wrong. Why should you own up to a mistake? You never make mistakes, right? You, the author of drivers and brilliant non-portable C code for the last ten years... Mistakes are beneath you, aren't they? You probably already knew that the "32-bit" Pentium released all the way back in 1993 had eight lots of 128-bit registers, and had a 64-bit data bus. You probably knew that the term "32-bit" is just a meaningless brand name.

Please find your emotional validation elsewhere; people come here to educate themselves, not to fulfill your ego. We all make mistakes, but we don't hold on to those mistakes despite evidence to the contrary, let alone pass those mistakes onto other students. That would make us delusional and sadistic, which are both traits of a mental illness. Have you considered seeing a psychologist about your mental illness?

The bottom line is: int x = strlen(...); is a mistake. Own it and move on.
0 Laura Lee · December 27, 2015
I never said size_t is four bytes. size_t is a typedef which conforms to the size depending on the architecture it is being compiled on. The return type of strlen has to do with the size that can be addressed which is the size of the pointer which is the max addressing value depending on the architecture.
What I stated was, chances are the user is compiling 32 hence size_t and int is irrelevant.
0 Linguist Llama · December 27, 2015
What does the return type of strlen have to do with an architecture?

... and what makes you think an int or a size_t is four bytes?

Please tell me, what type does strlen return?
0 Laura Lee · December 25, 2015
The length of the string is irrelevant. Chances are, the user is compiling for 32 bit and can easily fit any string the user enters in a signed four bytes. I'm well aware of size_t conforming to the architecture it is being compiled on. Similarly, my compiler will not even allow me to compile if the architecture is set to 64 bit and I am using a four byte to store a length of a string.
0 Linguist Llama · December 25, 2015
Laura, what is the type of strlen(str)?
0 Laura Lee · December 24, 2015
@Krootushas gesu, my code works fine. But the default code editor seemed to have removed the dereferencing of the str pointer. [\i\] is actually treated as an italic block, on this posting system.
0 Jasmin Bakalović · December 22, 2015
It would be good to paste a whole program and output of the console (use:

Until you do that I'll paste what I've done, maybe it can help you:
0 Laura Lee · December 21, 2015
int i = 0;
int numberofu = 0;
int length = strlen(str);
for(i ; i < length; ++i)
if(str == 'u')

  • 1



One of the most popular languages of all time.

Bucky Roberts Administrator