Advertisement
sellmmaahh

OR-skripta Adijata-zad3

Aug 25th, 2015
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.06 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. int obrni(int broj)
  5. {
  6.     int novi=0;
  7.     while(broj!=0)
  8.  
  9.     {
  10.         novi*=10;
  11.         novi+=broj%10;
  12.         broj/=10;
  13.  
  14.     }
  15.     return novi;
  16. }
  17.  
  18. char *Zamijeni (char *string) {
  19.     char *p=string;
  20.     char novi[100];
  21.     char *s=novi;
  22.     int suma=0;
  23.  
  24.     while (*p!='\0'){
  25.             if (*p>='0' && *p<='9') {
  26.                     while (*p>='0' && *p<='9') {
  27.                             suma+=*p-'0';
  28.                           p++;
  29.                     }
  30.                     obrni(suma);
  31.                     while (suma!=0) {
  32.                      *s++=(char)(suma%10+'0');
  33.                       suma/=10;
  34.                     }
  35.             }
  36.             else *s++=*p++;
  37.     }
  38.     *s='\0';
  39.     strcpy(string, novi);
  40.     return string;
  41. }
  42.  
  43. int main () {
  44.     char s[]="Na Antartiku ima 254 pingvina i 13 polarnih medvjeda.";
  45.     char nova[100];
  46.     char *poc=nova;
  47.     poc=Zamijeni(s);
  48.     while (*poc!='\0') {
  49.             printf("%c", *poc);
  50.     poc++;
  51.     }
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement