Thread: Program crashes when a loop is meant to begin

  1. #16
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    The way to delete a record is --- well actually -- you don't wanna delete it.

    As it turns out, it's great having some deleted records in your database. Because that's where you will stick in new records, without having to shift all the rest around, as much.

    For a deleted record, just remove the primary key - whether it's an ID number set to zero, or whatever. Also, put an end of string char as the first char in the name field:

    Smith, becomes \0mith. Now you have these deleted records in your data file, so you set your printing function not to print empty records:

    Code:
    for(i = 0; i < MaxNumber; i++) {
      if(ID) {
         printf("\n Name: %s   ID: %d  Phone Number: %s", recs[i].name, recs[i].ID, recs[i].phone);
      }
    }
    When you need to add a record, you just have your add function locate an already empty slot:

    Code:
    for(i = 0; i < MaxNumber; i++)  {
       if(ID == 0) {
          //found one that's empty, add the record data code right here
       }
    }
    What have we accomplished with this? We just shift our records around, a lot less. Make a few adjustments to our code, and we're good to go. It's easy enough to shift records, but when you have a large number of records, it's just not what you want to waste computer time, doing.

  2. #17
    Registered User
    Join Date
    Feb 2010
    Posts
    28
    Thank you, Adam!

    The help I have received from this forum is amazing. Can I ask everyone your motivation for helping people on here? Is it purely out of satisfaction from helping people?

  3. #18
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by m88g88 View Post
    Thank you, Adam!

    The help I have received from this forum is amazing. Can I ask everyone your motivation for helping people on here? Is it purely out of satisfaction from helping people?
    Oh no!

    I have your address now, from my high-tech sleuthing program. You can expect a large bill at the end of the month.

  4. #19
    Registered User
    Join Date
    Feb 2010
    Posts
    28
    Lol it's okay. Have everything. It's not mine!

  5. #20
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    m88g8:
    I cannot speak for everyone but many years ago I accidentally became an C++ instructor and realized that teaching is something that I love. Plus when I was learning C and C++ there were no locally-available classes on it and I had to teach myself. I was just trying to save you the pain.
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

  6. #21
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by m88g88 View Post
    The help I have received from this forum is amazing. Can I ask everyone your motivation for helping people on here? Is it purely out of satisfaction from helping people?
    Actually I learned C, on cboard, by pretending I know what is going on. If you just ask an innocent question, you may or may not get an answer eventually. But if you give someone else bad advice, a bunch of other people will straighten you out right away.

    Just kidding (mostly). I don't mislead or present something I am uncertain of as truth. But I did find that once I was at a certain point, people would ask questions that I could not answer off the top of my head but I knew I could figure out with a little work and experimentation. Even if it took me 15-30 minutes (sometimes more) I would sit and do the work and experimentation they should have done to figure it out. Pretty often I came up with a good solution and there are, of course, people who will correct you when you are wrong.

    I learned a lot this way: most beginner questions deal with fundamental issues -- if you don't know the answer, you will almost certainly have to learn it eventually. Learning it when I didn't need to meant that later when coding -- when I did need to know -- I already did. Also, programming is like most other skills: it gets easier with repetition. Eg, demonstrating the same principles over and over again. The demonstration may even improve in fundamental ways over time; you get lots of input from others.

    So while I would like to pretend to be an altruist because I answer way more questions than I ask, this is not totally true; I tend to benefit in the process too. However, I do think forums are one of the best programming resources you could possibly desire. Nothing beats a good forum (or mail list, but they are slower) when you are up some strange creek and have never heard of a "paddle". Also, you are in close communication with other programmers. Hence, I'm happy to try and make that possible on whatever level I can. There's a lot to learned from just reading some threads, and you can't leave it up to the same three or four people to write all of them.
    Last edited by MK27; 02-20-2010 at 12: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

  7. #22
    Registered User
    Join Date
    Feb 2010
    Posts
    28
    So while I would like to pretend to be an altruist because I answer way more questions than I ask, this is not totally true; I tend to benefit in the process too. However, I do think forums are one of the best programming resources you could possibly desire. Nothing beats a good forum (or mail list, but they are slower) when you are up some strange creek and have never heard of a "paddle". Also, you are in close communication with other programmers. Hence, I'm happy to try and make that possible on whatever level I can. There's a lot to learned from just reading some threads, and you can't leave it up to the same three or four people to write all of them.
    This seems like a really good idea for learning programming and you help others in the process. Maybe I'll do that when I have time to learn it properly lol.

    I haven't had time to learn to code from the beginning, which I why I'm struggeling so much! But in the holidays, there will be

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Loop issue in tax program
    By mistymoon1966 in forum C Programming
    Replies: 4
    Last Post: 10-31-2009, 02:04 PM
  2. Loop Entire Program?
    By seanminator in forum C Programming
    Replies: 25
    Last Post: 07-22-2009, 01:23 PM
  3. funcion runs 14 times, then program crashes
    By happyclown in forum C Programming
    Replies: 9
    Last Post: 03-03-2009, 11:58 PM
  4. Using While Loop to write a program
    By Cyberman86 in forum C++ Programming
    Replies: 2
    Last Post: 09-16-2008, 12:52 PM
  5. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM