![]() |
replace the "*" in the above string with " ", a single space character using ANSI C??
ok, I am very new to C programming and i have a problem at hand, i wuld really really appreciate any help plz,
The string is defined as the following: char * foo = " Baltimore *MD*is*a*really*good*place*to*work*and*play"; Using the smallest amount of code possible, replace the "*" in the above string with " ", a single space character using ANSI C language. The resulting string should be printed out at the end of the program. In addition to a manual examination, the resultant .C file will be compiled with GCC compiler with the "-ansi" flag set and executed to determine success CAN SOMEBODY HELP PLEASE? |
Re: replace the "*" in the above string with " ", a single space character using ANSI C??
We'd be glad to help, however we don't do your work for you. Refer to your lessons, work out some come, and present it for help with any problems you encounter. Be sure to read the "Before you make a query" thread (upper right corner of this page) before you post code -- code snippets should be inside code tags. You can learn about them there.
|
Re: replace the "*" in the above string with " ", a single space character using ANSI C??
You need to be looping through each member and if some character match is found you need to be replacing it with the new character.
|
Re: replace the "*" in the above string with " ", a single space character using ANSI C??
You can also use standered function strtok( ) .Take a char pointer and allocate it memory enough to hold the string.call strtok for tokens and append space at the last of each token and copy first token to string then concadinate others.
|
Re: replace the "*" in the above string with " ", a single space character using ANSI C??
also put terminating char in the last of string.
|
Re: replace the "*" in the above string with " ", a single space character using ANSI C??
ok here is the code i made
Code:
#include <stning.h> |
Re: replace the "*" in the above string with " ", a single space character using ANSI C??
He does not want to tokenize the string, he want to replace occurences of one character with other. There's no point in doing it in an unwieldy and inefficient way.
On most operating systems the current string, as defined, wil be const. That is, he will not be able to write to it. This will require copying the string, while replacing the characters on the fly. The terminating zero is already there, it just needs to be included in the copy. |
Re: replace the "*" in the above string with " ", a single space character using ANSI C??
[QUOTE=hardik]ok here is the code i made
Code:
#include <string.h> |
Re: replace the "*" in the above string with " ", a single space character using ANSI C??
[QUOTE=hardik]
Quote:
|
Re: replace the "*" in the above string with " ", a single space character using ANSI C??
We normally don't solve people's homework for them, Hardik. We help THEM solve it. It is how one learns. I'm making an exception in this case because you are complicating the problem unduly, and doing the original poster a huge disfavor.
Code:
#include <stdio.h>Quote:
|
| All times are GMT +5.5. The time now is 08:35. |