C program to trim blank spaces

#include <stdio.h>

void copy(char *to, char *from);

int main(void)
{

char str[80];

copy (str,” this ia a test “);

printf(“without spaces:%s”,str);

return 0;

}

void copy(char *to, char *from)

{

const char *p; char *q;

for(p=from,q=to;*p != ‘ ‘; p++)

// space between quotes in the above statement
{

if (*p != ‘ ‘) { *q=*p; q++; }

}

*q = ”;

}

// Download here.

// trim.doc

Tips: This function can be modified to find and replace a char.

See this page for an example Find and Replace

See this page for string replace: string replace

Advertisements

4 thoughts on “C program to trim blank spaces

  1. Pingback: C Find and Replace program « Applied Electronics Journal

  2. Pingback: C Find Replace Program « Applied Electronics Journal

  3. wonderful publish, very informative. I’m wondering why the other specialists of this sector do not notice this. You should continue your writing. I am confident, you’ve a huge
    readers’ base already!

  4. Hi there, I found your blog by the use of Google while searching
    for a similar subject, your web site came up, it appears to be like good.
    I’ve bookmarked it in my google bookmarks.
    Hi there, simply turned into alert to your weblog through Google, and located that it is really informative. I’m gonna be careful for brussels.

    I’ll be grateful in case you continue this in future. Lots of folks will probably be benefited from your writing. Cheers!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s