Advertisement
Adijata

string s brojevima

Sep 21st, 2014
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.54 KB | None | 0 0
  1. #include <stdio.h>
  2. char* funkcija (char rijec[], int k)
  3. {
  4.     char*s =rijec;
  5.     char nova[70];
  6.     char *p=nova;
  7.     int broj;
  8.     int minus=0;
  9.  
  10.     while(*s != '\0')
  11.     {
  12.         while(*s!='\0' && *s!=' ')
  13.         {
  14.             if (*(s-1)=='-' && *s>='0'&&*s<='9') minus=1;
  15.  
  16.  
  17.             if(*s>='0'&&*s<='9')
  18.             {
  19.                 broj=0;
  20.                 while (*s!='\0' && *s>='0'&&*s<='9')
  21.                 {
  22.                     broj*=10;
  23.                     broj+=(int) (*s- '0');
  24.                     *p++=*s++;
  25.  
  26.                 }
  27.                 if(minus==1) broj*=-1;
  28.                 if(broj>k)
  29.                 {
  30.                     *p++=' ';
  31.                     *p++='j';
  32.                     *p++='e';
  33.                     *p++='s';
  34.                     *p++='t';
  35.                     *p++='e';
  36.                     *p=' ';
  37.                 }
  38.                 else
  39.                 {
  40.  
  41.                     *p++=' ';
  42.                     *p++='n';
  43.                     *p++='i';
  44.                     *p++='j';
  45.                     *p++='e';
  46.                     *p=' ';
  47.                 }
  48.                 minus=0;
  49.             }
  50.  
  51.             *p++=*s++;
  52.         }
  53.         *p++=*s++;
  54.     }
  55.     *p='\0';
  56.     strcpy(rijec, nova);
  57.     return rijec;
  58. }
  59. int main()
  60. {
  61.     char recenica[100] = "prije125 nov258 brojk-566 -kl879 26999";
  62.     char nova[100];
  63.     char*p =nova;
  64.     p=funkcija(recenica,150);
  65.     while(*p!='\0')
  66.     {
  67.         printf("%c", *p++);
  68.     }
  69.  
  70.     printf(" veci od %d", 150);
  71.  
  72.  
  73.     return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement