I am am for the first time here,since it is the first time I needed help.I have read all the rules and I agree with you for the homework case...But this is getting frustrating!I am working on this on my own,practicing for the mid term but what am I doing wrong?

#include <iostream>
#include <string>
using namespace std;
void main ()
{
	int i;
	char is[]="Vnesi string: ", vs[100];
    cout<<is;
    cin.getline(vs, 100);
    cout<<vs<<endl;
	char im[1];
	im[0]='p';
	for(i=0;i<strlen(is);i++)
	{
		if(is[i]=='d')strcpy(&is[i],im[0]);
		
		cout<<is;
	}
	cin>>is;
	
    

}

It keeps returning this error and soma more if i change something:(cannot convert parameter 2 from 'char' to 'const char *'
I will appreciate your help very much,I would love to get this cleared.
Btw,my assignment is to replace one character with another.I know strcpy is just coping but that was the best I could think of.Thanks again.
This string thing really confuses me...

>>strcpy(&is,im[0]);
Look at the second parameter -- it is not a char*

That line can be written without using strcpy() if(is[i]=='d') is[i] = im[0]; or even more simply if(is[i]=='d') is[i] = 'p';

But it sill doesn't work..It Asks for this information "Vnesi string: "..and than repeats that as an exit "Vnesi string: " The word "Vnesi" means to input...
Anyway what is wrong?Once it turned out right,but I tried to make it even better and messed it up.
My goal is,as I said,to replace characters in a string...
Thank you for your quick response:)

it keeps repeating that because you told it to repeat it in line 17. If you don't want it repeated then move line 17 outside that loop.

#include <iostream>
#include <string>
using namespace std;
void main ()
{
	int i;
	char is[]="Vnesi string: ", vs[100];
    cout<<is;
    cin.getline(vs, 100);
    cout<<vs<<endl;
	char im[1];
	im[0]='p';
	for(i=0;i<strlen(is);i++)
	{
		if(is[i]=='d') is[i] = 'p';
		
		
	}
	cout<<is;
	cin>>is;
	
    

}

I did this and now it asked me twice to make an input and than shut down.Seems like it is not eve getting to the for ,and not to mention if...

try reading what you posted. Your program is only doing exactly what you told it to do. Look at the last two lines and you will see for yourself why it is asking you to enter the string twice.

True.You know I always do that mistake.

#include <iostream>
#include <string>
using namespace std;
void main ()
{
	int i;
	char is[]="Vnesi string: ", vs[100];
    cout<<is;
    cin.getline(vs, 100);
    cout<<vs<<endl;
	char im[1];
	im[0]='p';
	for(i=0;i<strlen(is);i++)
	{
		if(is[i]=='d') is[i] = 'p';
		
		
	}
	system("Pause");
	
    

}

But I corrected it.Now we can point to the main mistake...It 5.32 am where I am now,and I am not giving up into solving strings completely...

>>It 5.32 am where I am now
GO TO SLEEP! You can't learn very well when you are that tired. The world will not come to an end if you get a good night's sleep. Tomarrow is just another day in your life. Good night, I'm going to sleep too (10:36 pm at my house).

:)Ok I will ..but I will get to it tomorrow,I hope will find help again here.Thank you for your effort!

This article has been dead for over six months. Start a new discussion instead.