Thread: question about strings!

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    63

    question about strings!

    hi,
    say I have an array of strings consisting of names..now if I want to delete one of the names & move the list up how would I do that..basically..how would I overwrite that name?
    A

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    247
    basically the answer is to swap the array around. You know, from your deleted string in the array go up the elements swapping them
    Code:
    for(i = whatever element your string to delete is; i < elements in the array - 1; i++)
         for(j = whatever element your string to delete is + 1; j < elements in the array; j++) {
                 strcpy(temp,string[i]);
                 strcpy(string[i], string[j]);
                 strcpy(string[j], temp);
    }
    /* your string to delete is now at the last element */
    /* so delete it by copying a null */
    strcpy(string[i], "\0");
    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. Question about strings in c
    By gp364481 in forum C Programming
    Replies: 9
    Last Post: 11-13-2008, 06:32 PM
  2. Question About Strings
    By spanker in forum C++ Programming
    Replies: 1
    Last Post: 07-13-2008, 05:09 AM
  3. strings question
    By cstudent in forum C Programming
    Replies: 4
    Last Post: 04-18-2008, 07:28 AM
  4. Functions and Strings Question
    By StrikeMech in forum C Programming
    Replies: 4
    Last Post: 07-18-2007, 06:07 AM
  5. Strings question
    By kimimaro in forum C Programming
    Replies: 10
    Last Post: 03-15-2005, 12:14 AM