Thread: inserting a space

  1. #1
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926

    inserting a space

    How would I go about inserting a space into an array I have gotten, say from a file. ex
    Code:
    fgets(array,sizeof array,file);
    Now where would I go. I don't want to create a new array or use malloc. Is there a way with say pointers or something? TIA

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Does the existing array contain enough room?

    Since you are using fgets I'm assuming an array of characters and specifically a null terminated array

    To say insert a space after the 4th element
    Code:
    for ( c = strlen(array) /* Want to move null character also */; c > 3; c--)
    {
      array[c+1] = array[c];
    } 
    
    array[c+1]=' ';
    This will only work if you have enough room in the array already.

  3. #3
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    thanx

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Out of space when compiling kernel
    By NuNn in forum Linux Programming
    Replies: 3
    Last Post: 04-01-2009, 02:43 PM
  2. disk space mysteriously gone
    By evader in forum C++ Programming
    Replies: 4
    Last Post: 01-21-2004, 01:30 PM
  3. Replies: 12
    Last Post: 05-17-2003, 05:58 AM
  4. someone who is good at finding and fixing bugs?
    By elfjuice in forum C++ Programming
    Replies: 8
    Last Post: 06-07-2002, 03:59 PM