[Tutor] C program

Alondt Yauk fiveholiday55 at hotmail.com
Wed Aug 1 10:35:33 CEST 2007


Thanks very much, I will try it out and use your idea.
Am sorry I posted the question in this forum, just wanted to get ideas from 
you guys.

Ciao

----- Original Message ----- 
From: "Tiger12506" <keridee at jayco.net>
To: <tutor at python.org>
Sent: Wednesday, August 01, 2007 3:20 AM
Subject: Re: [Tutor] C program


> Hello people of the world.
>
> This question is not a Python related question, but I thought I might just
> throw it in here and see if there are any C old-timers who could help out.
>
> I have a string with space and I would like to remove the space before
> comparing but I don't know how to go about doing it. Here is the code
>
> int result = strcmp("yes","yes ");//trailing space on the second yes
> this should give me '0' meaning they are both the same, but with the 
> space,
> it gives me '-1'
>
> Please note: those arguments can be supplied by the user, and when they 
> do,
> I want to strip off the trailing space.
>
> Any helps is highly appreciated.
> ---------------------
>
> I doubt if this is the best way, but you can do this.
>
>
> /*--------------------------------------------------*/
> #include <stdlib.h>
> #include <stdio.h>
>
> char s[20] = "yes";
> char s2[20] = "yes      ";
>
> void rstrip(char *c) {
>  while (*c++!=0);
>  c--;
>  while (*--c==' ') *c = 0;
> }
>
> int main() {
>  rstrip(s2);
>  int result = strcmp(s, s2);
>  printf("%d\n",result);
>  system("pause");
> }
> /*------------------------------------------------------*/
>
>
> JS
>
> PS - This *is* a python list. Usually the tutors don't like people who 
> post
> off-topic stuff. (And C is pretty off-topic)
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 



More information about the Tutor mailing list