Advertisement
Adijata

izbaci najveci broj iz stringa tacno

Sep 10th, 2014
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.50 KB | None | 0 0
  1. #include <stdio.h>
  2. char* funkcija (char rijec[], int k)
  3. {
  4.     char*s =rijec;
  5.     char *r= rijec;
  6.     char nova[70];
  7.     char *p=nova;
  8.     char *q, *maxq;
  9.     int broj,brojac, maxbrojac,i;
  10.     int maks=-99999999;
  11.     int minus=0;
  12.  
  13.     while(*s != '\0')
  14.     {
  15.         while(*s!='\0' && *s!=' ')
  16.         {
  17.             if (*(s-1)=='-' && *s>='0' && *s<='9') minus=1;
  18.  
  19.             if(*s>='0' && *s<='9')
  20.             {
  21.                 broj=0;
  22.                 brojac=0;
  23.                 q=s;
  24.                 while (*s!='\0' && *s>='0'&&*s<='9')
  25.                 {
  26.                     broj*=10;
  27.                     broj+=(int) (*s- '0');
  28.                     s++;
  29.                     brojac++;
  30.  
  31.                 }
  32.                 if(minus==1) broj*=-1;
  33.                 if(broj>maks)
  34.                 {
  35.                     maks=broj;
  36.                     maxq=q;
  37.                     maxbrojac=brojac;
  38.                 }
  39.  
  40.                 minus=0;
  41.             }
  42.             s++;
  43.         }
  44.         s++;
  45.     }
  46.     while(*r!='\0')
  47.     {
  48.         if(r==maxq)
  49.         {
  50.             for(i=0; i<maxbrojac; i++)
  51.             {
  52.                 r++;
  53.             }
  54.         }
  55.         *p++=*r++;
  56.     }
  57.  
  58.     *p='\0';
  59.     strcpy(rijec, nova);
  60.     return rijec;
  61. }
  62. int main()
  63. {
  64.     char recenica[100] = "najveci broj u stringu nije -9999, vec je 0";
  65.     char nova[100];
  66.     char*p =nova;
  67.     p=funkcija(recenica,150);
  68.     while(*p!='\0')
  69.     {
  70.         printf("%c", *p++);
  71.     }
  72.  
  73.  
  74.  
  75.  
  76.     return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement