whats "one off"
i searched in google there is no definition
whats "one off"
i searched in google there is no definition
Obviously need to practice your google skills - http://en.wikipedia.org/wiki/Off-by-one_error
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Last edited by MK27; 01-28-2009 at 04:39 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
i debugged it again
and when i=7 (the last char before enter)
i goes to
so i guessed i[7] gets the \n charCode:if ((ch=='\n')&&(i!=size)) { return 0; }
so i changed i==size-1
now it returns 1 but
it doesnt put the 8th number in the array
??
Code:#include <stdio.h> int read_array(int input[],int i,int size); int main() { int i; int input[40]; printf("%d\n",read_array(input,0,8)); for(i=0;i<8;i++) { printf("%d ",input[i]); } printf("\n"); return 0; } int read_array(int input[],int i,int size) { int flag,rt,ch; if (i==size-1) { return 1; } flag=scanf("%d",&input[i]); ch=getchar(); if ((ch=='\n')&&(i!=size)) { return 0; } if (ch<0) { return 0; } if (flag==0) { return 0; } else { } rt=read_array(input,i+1,size); return rt; }
Last edited by transgalactic2; 01-29-2009 at 02:27 AM.
So what do you think you should do to fix that?
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
i should some how catch this eights char using getchar
and put it into the array
but where to do that?
Think about what happens in your code, and where you get to for each possible scenario of newlines, count of i, and numbers entered. Where should you exit the recursion? What are the conditions?
Coding is about solving problems - you _NEED_ to learn to think about what happens in your code, not just repeatedly post "and how do I do that?"
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
i get \n only onces i the end of the array
i dont know why it happens
thats how it should be
a row of numbers and enter
what is the problem?
one new line means one enter
Last edited by transgalactic2; 01-29-2009 at 08:38 AM.
i solved it thanks
how to check if there are more member then the size??
If you count to MORE than size and haven't received a newline yet, is that a good enough clue?
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
nothing stops me from counting further
so its not much an obsticle