by Dinesh Thakur Category: Puppetting On Strings

Single characters can be replaced in a string. Given the following declarations, several things are possible.

 

char str[25] = "cot";

char ch = 'u';

char D[25] = "pat";

 

  • Replacing a single character using a char variable:
  • D[1] = ch;

This would result in D containing "put".

  • Replacing a single character using a char literal:
  • D[1] = 'e';

This would result in D containing "pet".

  • Replacing a single character using a single character from a string

variable:

  • D[1] = str[1];

This would result in D containing "pot".

 



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.