J
juvenuts
Hi, I'm a complete newbie to C, but I wanted to get started by writing
a few simple programs that print out strings.
1. The first thing I wanted to do was write a program that uses getchar
to read one letter at a time, and uses printf to print it out as
entered. I also wanted to make it terminate when the EOF character is
entered.
2. I also wanted to add to this by writing another program that prints
out a string, ignoring everything that follows a specified character
until a new line is found..
e.g. if I wanted to ignore everything after the % character and the the
input is
This is a string of text % BLAHBLAHBLAH
% BLAHBLAHBLAH
This is a string of text
Then the output will be
This is a string of text
This is a string of text
3. I know these programs might be getting a bit repetitive for all you
experienced C programmers, but I'd like to make a bunch of variations,
the next one being this: I'm aware that there is an "ispunct" function,
so I wanted to write a program that removes punctuation from input
strings.
4. Finally, how would I program simple substitutions for specified
characters in a string? e.g. say I wanted to substitute every
occurrence of "a" with "BANG!"
e.g. "I am a newbie to C programming" would turn into
"I BANG!m BANG! newbie to C progrBANG!mming"
Any help would be very much appreciated, thanks in advance.
a few simple programs that print out strings.
1. The first thing I wanted to do was write a program that uses getchar
to read one letter at a time, and uses printf to print it out as
entered. I also wanted to make it terminate when the EOF character is
entered.
2. I also wanted to add to this by writing another program that prints
out a string, ignoring everything that follows a specified character
until a new line is found..
e.g. if I wanted to ignore everything after the % character and the the
input is
This is a string of text % BLAHBLAHBLAH
% BLAHBLAHBLAH
This is a string of text
Then the output will be
This is a string of text
This is a string of text
3. I know these programs might be getting a bit repetitive for all you
experienced C programmers, but I'd like to make a bunch of variations,
the next one being this: I'm aware that there is an "ispunct" function,
so I wanted to write a program that removes punctuation from input
strings.
4. Finally, how would I program simple substitutions for specified
characters in a string? e.g. say I wanted to substitute every
occurrence of "a" with "BANG!"
e.g. "I am a newbie to C programming" would turn into
"I BANG!m BANG! newbie to C progrBANG!mming"
Any help would be very much appreciated, thanks in advance.