The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum
 Origin Forum
 Trying a trim function
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

zivchen

Taiwan
Posts

Posted - 12/11/2007 :  10:55:26 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
I am a beginner of c language, and trying to use trim function in a main. But I don't know what going on with my program? So please correct me. Thank you so much

The program is as follow:

#include<stdio.h>
#include<string.h>

int trim(char s[])
{
int n;

for (n = strlen(s)-1; n >= 0; n--){
if (s[n] != ' ' && s[n] != '\t' && s[n] != '\n')
break;}
s[n+1] = '\0';
return 0;
}

main()
{
char s[30] = "fly egle\t and\n fly again";
trim(s);
printf("%s\n",s);
}
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000