Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replace a single character in a char array

Status
Not open for further replies.

cyprus106

Programmer
Apr 30, 2001
654
0
0
Alright... I want to run through a 'for' loop and replace every character in my buffer, called 'mybuf[256]', with a 'Z', output that to my screen (which is no problem), then replace the 'Z' character with the character that I just took out. (Basically, save whatever character was just overwritten in the buffer and put it back in)

So this would be an example:
CYPRUS106 1
ZYPRUS106 2
CZPRUS106 3
CYZRUS106 4
CYPZUS106 5
CYPRZS106 6
and so on...

I'm just lowly quality assurance and haven't worked with C++ or C code in a long time. My logic's off in my for loop and I don't know how to fix it. Just so I don't get flamed, this isn't homework. I'm trying to run a partial record rewrite test against a server to be sure this new function works...

Cyprus
 
Hey Cyprus,
Try something like this, if I understand it alright.
Code:
char mybuf[256];
char tempchar;
int i;
//You need initialize mybuf with what ever you want here
for(i=0;i<256;i++){
 printf("%s",mybuf);
 if(i!=0)
  mybuf[i-1]=tempchar;

 tempchar = mybuf[i];
 mybuf[i] = 'Z';
}

Hope this helps you somewhat.


-Jay
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top