www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/04/05/22:16:59

From: Imp <gilley AT netunlimited DOT net>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Deleteing in a string
Date: Mon, 06 Apr 1998 00:15:09 +0000
Organization: NetUnlimited, Inc.
Lines: 88
Message-ID: <35281E8C.8A0138AF@netunlimited.net>
References: <01bd60d9$c33d8300$0f02000a AT frank DOT mtsu DOT edu DOT frank DOT mtsu DOT edu>
NNTP-Posting-Host: uhura-13.netunlimited.net
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Nathan Cournia wrote:

>         Here's a problem that I can't get a grasp on.  What I want to do is delete
> a character in a string but I'm having problems.  Here's the code:
>
> #include <iostream.h>
> #include <cstring>
> #include <fstream.h>
>
> typedef char string[21];
>
> main()
> {
>     string x;
>     ifstream myin;
>     myin.open ("test.dat");
>       //might want to check to see if you got the file open here
>     myin >> x;
>                 //lets take a look at the string first

             cout<<x;

>     char y;
>     for(int i=0; i<21; i++)
>     {
>          y=x[i];        //you really don't need, you could just compare on
> x[i]==','
>         if(y==",")  //double quotes are for a string, use single quates around
> single characters

                                 // ie.    ','

>
>             x[i]=x[i+1];

                                //you know what may make things strange here is that
if you

>                             //x[i] is now x[i+1] and next time through the loop
> x[i] is the same as x[i+1] was

                               //so you get two of what ever x[i+1]
was                               //why not do it as x[i]=x[i++];

>     }

           //you would want to see your result to see what happened          cout<<x;

> } //end of main
>
> FILE: test.dat
> Nathan, Bill, Joe,
>
>         Oh ya, the above doesn't work.  Cause ANSI C++ forbids comparison between
> pointer and integer.  Thanks for looking at this.
>
>         Nathan Cournia































- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019