yep.
Well, not anymore because I am using the command you gave me.
yep.
Well, not anymore because I am using the command you gave me.
Wow. What if you put a newline in there:
Which I know you don't want to do that in this case, but it could be your buffer isn't flushed until a newline (or the buffer is full) which wouldn't be unusual.Code:printf("Enter an index: \n");
It really is about the OS, by the way. But if you are used to Java, the Java VM/interpreter probably includes a mechanism to make it's own behavior uniform, taking the OS's behaviour into account. As you point out, C is not so fancy.
Last edited by MK27; 01-28-2010 at 01:26 PM.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
duly noted about card arrays.
Are you sure that strlen() does not require any non-standard libraries?
No, <string.h> is a standard library.
Also, sizeof will lie about the length of strings like
Code:char s[100] = "Hello";
I might be wrong.
Quoted more than 1000 times (I hope).Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
strlen should be in string.h
Edit:
what the hell? Before I posted this then bright's question about strlen() was the last reply and now when I click submit 2 more replies pop up.. forum bug?
Last edited by _Mike; 01-28-2010 at 04:02 PM.
It was my impression that sizeof didn't lie so much as it just includes the null terminator at the end of a C-style char array
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
char s[100] = "Hello";
sizeof(s) == 100
strlen(s) == 5
char* s = "This is a long string!";
sizeof(s) == 4
strlen(s) == 22
Using sizeof for string length is not reliable..