Is there another way to write this program?
Hi. Our assignment was to write a program that accepts lines of text which the user types, and display them in the politically correct non-sexist form by changing all occurrences of the strings "man" to "person" and "Man" to "Person."
For example:
Enter a string: Amanda Peterman
Apersonda Peterperson
PHP Code:
#include <stdio.h>
#include <string.h>
char *replace(char userstr[]);
void main(){
char userstr[100];
printf("Please enter a line *if you wish to exit, press Enter* : ");
/*Now goes to function replace*/
replace(userstr);
}
char *replace(char userstr[]){
int i;
/*Unless the user doesn't enter anything, it will go through these steps*/
while(gets(userstr) && strlen(userstr) != 0){
i = 0;
while(i != strlen(userstr)){
/* while loop - while the length of the user's string doesn't equal i(0), it will go through these steps*/
/* it will go through these steps if "Man is in a string */
if(*(userstr + i) == 'M' && *(userstr + i + 1) == 'a' && *(userstr + i +
2) == 'n'){
printf("Person");
i = i + 3;
}
/* else if "Man is in a string it will go through these steps*/
else if(*(userstr + i) == 'm' && *(userstr + i + 1) == 'a' && *(userstr +
i + 2) == 'n'){
printf("person");
i = i + 3;
}
/* else if "man" and "Man" is not found print the current character*/
else{
printf("%c", *(userstr + i));
i++;
}
}
printf("\n\nPlease enter a line *if you wish to exit, press Enter*: ");
}
return 0;
}
Now my program works the way it should but, my professor wants it arranged so that in the main program, it reads the string the user inputs, passes it to function replace, replace function converts it, return it back to main program, & prints the new string there. And he wants me to do all of this without using any of the string functions!!!! He wants us to use our own versions of the string functions. :mad: I don't see how this could possibly work, but if anyone can see how you can arrange it that way could you please show me how? :(
Thank You. :)