Adijata

sve cifre u brju postaviti na prvu cifru

Sep 21st, 2014
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.87 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. char* funkcija(char string[])
  6. {
  7.  
  8.     char* p = string;
  9.     char nova[80];
  10.     char *s = nova;
  11.     char cifra;
  12.  
  13.     int i = 0,brojac;
  14.     while(*p != '\0')
  15.     {
  16.         if(* p >= '0' && *p <= '9')
  17.  
  18.         {
  19.             cifra = *p;
  20.             brojac = 0;
  21.  
  22.             while(*p != '\0' && *p >= '0' && *p <= '9')
  23.             {
  24.                 p ++;
  25.                 brojac ++;
  26.             }
  27.  
  28.             for(i = 0; i < brojac; i ++)
  29.             *s ++ = cifra;
  30.            
  31.         }
  32.         *s ++ = *p ++;
  33.     }
  34.     *s = '\0';
  35.  
  36.     strcpy(string, nova);
  37.     return string;
  38. }
  39.  
  40. int main()
  41. {
  42.  
  43.     char rijec[88]= {"Neki broj -5659, 9755, 3241"};
  44.  
  45.     char nova[88];
  46.     char* p = nova;
  47.  
  48.      p=funkcija(rijec);
  49.  
  50.     while(*p != '\0')
  51.     {
  52.         printf("%c", *p ++);
  53.     }
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment