Mail Archives: djgpp/1998/04/05/22:16:59
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 -