-1

Can some body know a function that removes white spaces in begining and end and also removes '\n' or '\0' from a file in C language

Votes + Comments
Make your own thread about it.
3
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by Dream2code
0

In C language the fgets() function will trim leading and trailing spaces from words read. It will also skip over '\n'. Text files do not contain '\0' bytes; if your file does then it is not a text file.

0

In C language the fgets() function will trim leading and trailing spaces from words read. It will also skip over '\n'. Text files do not contain '\0' bytes; if your file does then it is not a text file.

may be you are confused with fread().

fgets will read line by line from a file.it will read until the \n. or length spefied which comes 1st.

-2

Here is your function for sting lrtrim:

/*****THIS FUNCTION IS USED TO REMOVE SPACES FROM THE LEFT AND RIGHT OF A STING*******
|       EXAMPLE
|       -------
|       Input String:"    i am going to school     "
|       Output String:"i am going to school"
*************************************************************************************/


char* str_lrtrim(char *base_str)
 {
  int len=strlen(base_str);
  int i=0;

  if(base_str==NULL)
        return NULL;

  while(isspace(base_str[len-1]))
        {
          base_str[len-1]='\0';
          len--;
        }
  while(isspace(base_str[i]))base_str++;

 return base_str;
}


/******************************END str_lrtrim()*********************************/
Votes + Comments
Nope, no free cookies here.
This is the second post I've seen tonight where you GIVE code away. We do not give code here, we help them code it themselves.
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.