Results 1 to 5 of 5

Thread: Deleting space in a string in C programming

  1. #1
    Join Date
    Jul 2009
    Posts
    140

    Deleting space in a string in C programming

    Hello ,

    I am writing a program in c language but I am getting some difficulties during complexity of the spaces in the string.I want to remove the spaces from the string.Is there any function is available in c programming which can be used to remove the spaces between strings.

    Please,tell me the any possible solution for this programming technique.

    Thanks.

  2. #2
    Join Date
    May 2008
    Posts
    2,012

    Deleting space in a string in C programming

    You can delete the spaces between the string using manually defined or created function.you have to use your own logic to remove the spaces from the string.

    I don't think,Is there any function is inbuilt in c programming which can help you to do this.You have to assign the string manually and perform the fragmentation of string and after all represent the whole string in the order in which it was issued.

  3. #3
    Join Date
    Apr 2008
    Posts
    2,005

    Deleting space in a string in C programming

    You can do it very easily but there is no any pre-defined function in C programming which can do it.You have to define the variable which can contain string type values and construct an absolute output without any spaces.

    The following code can help you to perform this -

    int Rmspaces(char *str_val);
    int main()
    {
    char str;
    char *str_val = &str;
    char wrd;

    cout << "Enter a statemnt: ";
    cin >> *str_val;

    wrd = Rmspaces(str_val);

    cout << "No Spaces:" << wrd << endl;
    return 0;
    }

    int stripWhite(char *str_val)
    {
    char *pps;
    pps = str;
    do
    if (!isspace(*pps=*str_val))pps++;
    while (*str_val++);
    return *str_val;
    }

  4. #4
    Join Date
    May 2008
    Posts
    2,297

    Deleting space in a string in C programming

    There are so many users have different thinking and creativity for codding which generates different logic to solve the problem.To delete the space between the strings,you can use this given code also which is different from above written code.

    The code illustrated below -


    Code:
     void delspace (char *Str)
       {
    
          int Ptr = 0;
          int Dst = 0;
    
    while (String [Ptr])
    
          {
    
          if (String [Ptr] != ' ')
    
          Str [Dst++] = String [Ptr];
     
          Ptr++;
    
          }
    
           String [Ptr] = 0;
    
          }

  5. #5
    Join Date
    Oct 2005
    Posts
    2,393

    Deleting file in C programming

    You can delete a whole file in C using the available library function.The Remove function would be used to remove the supported file by the C compiler.

    we have included the library function named remove() which will deletes the file File.txt. In case if the file will not get deleted then one more function is added to show the error message named perror() to print the error message on the console.

    Code:
    #include <stdio.h>
    #include <conio.h>
    void main() {
      if (remove("file.txt") == -1)
        perror("The file can't be delete");
      getch();
    }

Similar Threads

  1. Replies: 6
    Last Post: 21-08-2011, 08:02 AM
  2. No free space even after deleting files As Root
    By NamJam in forum Operating Systems
    Replies: 5
    Last Post: 11-01-2011, 08:44 AM
  3. How to find string that doesn't start with empty space?
    By MACE in forum Software Development
    Replies: 4
    Last Post: 02-03-2010, 06:21 PM
  4. Managing space in string
    By Gunner 1 in forum Software Development
    Replies: 5
    Last Post: 10-02-2010, 03:53 AM
  5. Problem : No free space even after deleting files
    By LinuxeD in forum Operating Systems
    Replies: 2
    Last Post: 19-08-2009, 12:17 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,641,062.72388 seconds with 17 queries