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

William Hemsworth commented: Make your own thread about it. -2

Recommended Answers

All 3 Replies

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.

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.

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()*********************************/
commented: 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. -4
commented: Nope, no free cookies here. -3
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.