From: Imp 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 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk 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 > #include > #include > > 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< 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< } //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