9511_workbook

solved exercises from algorithms & programming I (9511) prof. Cardozo
Index Commits Files Refs README
guia03/ex14.c (409B)
   1 #include <stdio.h>
   2 
   3 
   4 typedef enum {
   5     OK, ERROR
   6 } status_t; 
   7 
   8 
   9 size_t rechar(char *str, char old, char new);
  10 
  11 
  12 int main( void ) {
  13 
  14     char str[] = "Hello world!";
  15 
  16     rechar(str, 'o', 'e');
  17 
  18     printf("%s\n", str);
  19     return OK;
  20 }
  21 
  22 
  23 
  24 size_t rechar(char *str, char old, char new) {
  25     if(str == NULL)
  26         return ERROR;
  27 
  28     int i;
  29     for(i = 0; str[i] != '\0'; i++) {
  30         if(str[i] == old) {
  31             str[i] = new;
  32         }
  33     }
  34     return OK;
  35 }