Thread: trying to read input into an array

  1. #16
    Kernel hacker
    Join Date
    Jul 2007
    Farncombe, Surrey, England
    Quote Originally Posted by trprince View Post
    sorry one other thing. This is working backwards for me. i get a -1 for ascending number (1 2 3 4 5). here is the code i have

    float ascend_arr(float aarry[], int sizearr){
      int ascend;
      for(ascend = 1; ascend < sizearr;){
        if (aarry[ascend] < aarry[ascend + 1]){
          return 1;
      return -1; 
    Try to keep one question in one thread, and not discussing the SAME problem in two different threads.

    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.

  2. #17
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
      int ascend;
      for(ascend = 1; ascend < sizearr;){
        if (aarry[ascend] < aarry[ascend + 1]){
    You start at 1 instead of 0, and you overrun the end of the array with aarry[ascend+1]. Oops. I think you meant
    for(ascend = 0; ascend < sizearr-1; ) {
    BTW, pronouncable variable names wouldn't hurt. "aarry" is just painful . . .

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell

    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ:

    My website:
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 12
    Last Post: 04-12-2009, 05:49 PM
  2. Read file into array
    By neobarn in forum C Programming
    Replies: 6
    Last Post: 01-09-2009, 12:41 PM
  3. read file list into array
    By deltaxfx in forum C Programming
    Replies: 1
    Last Post: 01-07-2006, 11:41 PM
  4. Replies: 1
    Last Post: 09-10-2005, 06:02 AM
  5. function to read an int from input
    By linucksrox in forum C Programming
    Replies: 8
    Last Post: 06-08-2004, 10:15 AM