Okay, long story short I am having some trouble: I'm trying to send the starting address of a character array (string) to a function. Once the function gets the pointer, I'd like the function to parse through the characters one by one (in order to modify certain characters). As of right now I just set it up to print each character, but I'm still failing at that really badly.
This is what I have:
#include "system.h"
#include <stdio.h>
typedef unsigned int uint32;
typedef unsigned short uint16;
typedef unsigned char uint8;
void EXCLAIM(char *msg){
char the_char = 0;
the_char = msg;
while (the_char != 0)
{
printf(the_char);
*msg = *(msg++);
the_char = *msg;
}
}
int main(void) {
char *first_str = "This is a test. Will this work. I. am. Not. Sure...";
while (1) {
EXCLAIM(first_str);
}
}
EDIT:
Here is the updated code with what I was trying to do; send the pointer and go through each character replacing all periods with exclamation marks.
#include "system.h"
#include <stdio.h>
typedef unsigned int uint32;
typedef unsigned short uint16;
typedef unsigned char uint8;
void exclaim(char *msg){
int i;
for( i=0; msg[i]; i++ )
{
if (msg[i] == '.') {
msg[i] = '!';
}
}
printf(msg);
}
int main(void) {
char *the_sentences = "This is a test. Will this work. I. am. Not. Sure...";
while (1) {
exclaim(the_sentences);
}
}
Thank you all for your help!