Thread: resetting arrays

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    14

    Question resetting arrays

    I'm getting a weird result in the attached program. Think it has something to do with the array or the get_word function. When I hit 'y' at the end to repeat it skip most of the program down to where it says "Congratulations".

    How do you reset an array to nothing? Do you need to do this everytime you read in a string using scanf?

    Much appreciate any help I could get.
    Thanx.

  2. #2
    Unregistered
    Guest

    Thumbs up

    Not read your program but in C you can do it this way

    eg.

    /* Simple array clearing program */

    #include <stdio.h>
    #define maxchar 10;

    main ()
    {

    int i;
    char my_string [maxchar];

    for (i = 0; i <= (maxchar-1); i++)
    my_string [i] = NULL;

    }


    This is required each time you use the array otherwise any text you try to print will contain text at the end from previous uses.

    Roger

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    247
    easier to do this

    strcpy(my_string, "\0");
    hoping to be certified (programming in c)
    here's the news - I'm officially certified.

  4. #4
    Unregistered
    Guest
    smart arse!

  5. #5
    Registered User
    Join Date
    Aug 2001
    Posts
    247
    thanks unregistered
    hoping to be certified (programming in c)
    here's the news - I'm officially certified.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Function to read in two arrays
    By ssmokincamaro in forum C Programming
    Replies: 7
    Last Post: 11-12-2008, 07:59 AM
  2. pointers & arrays and realloc!
    By zesty in forum C Programming
    Replies: 14
    Last Post: 01-19-2008, 04:24 PM
  3. Replies: 16
    Last Post: 01-01-2008, 04:07 PM
  4. Need Help With 3 Parallel Arrays Selction Sort
    By slickwilly440 in forum C++ Programming
    Replies: 4
    Last Post: 11-19-2005, 10:47 PM
  5. Crazy memory problem with arrays
    By fusikon in forum C++ Programming
    Replies: 9
    Last Post: 01-15-2003, 09:24 PM