Advertisement
Adijata

obrni brojeve u stringu

Sep 10th, 2014
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.81 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #define size 80
  5.  
  6. char* obrni(char* p, char novi[])
  7. {
  8.     char *s=novi;
  9.     int broj;
  10.  
  11.  
  12.     while(*p!='\0')
  13.     {
  14.         if(*p>='0' && *p<='9')
  15.         {
  16.             broj=0;
  17.             while(*p>='0' && *p<='9')
  18.             {
  19.                 broj*=10;
  20.                 broj+=(int)(*p-'0');
  21.                 p++;
  22.             }
  23.             while(broj!=0)
  24.             {
  25.                 *s=(char)(broj%10+'0');
  26.                 broj/=10;
  27.                 s++;
  28.             }
  29.  
  30.         }
  31.         *s++=*p++;
  32.     }
  33.      *s='\0';
  34.  
  35.     return novi;
  36. }
  37.  
  38. int main()
  39. {
  40.     char niz[50] = "Hrk255ljus789";
  41.     char novi[50];
  42.     char *p=novi;
  43.     *p=obrni(niz, novi);
  44.  
  45.     while(*p!='\0')
  46.     {
  47.         printf("%c", *p++);
  48.     }
  49.     return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement